Skip to content

Commit d3f7e50

Browse files
committed
Add .test.js suffix to test files
1 parent fb0246a commit d3f7e50

22 files changed

+112
-14
lines changed
File renamed without changes.

test/async/evaluate.js renamed to test/async/evaluate.test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const { strict: assert } = require('assert');
44
const { evaluate } = require('../support');
55

66
const opts = { functions: true, allowAwaitOutsideFunction: true };
7-
const e = (input, context, options) => evaluate(input, context, { ...opts, ...options });
8-
e.sync = (input, context, options) => evaluate.sync(input, context, { ...opts, ...options });
7+
const e = (input, data, options) => evaluate(input, data, { ...opts, ...options });
8+
e.sync = (input, data, options) => evaluate.sync(input, data, { ...opts, ...options });
99

1010
describe('evaluate', () => {
1111
describe('async', async () => {
@@ -244,6 +244,16 @@ describe('evaluate', () => {
244244
assert.equal(await e('string && focused.editable', context), false);
245245
assert.equal(await e('!!(string && focused.editable)', context), false);
246246
});
247+
248+
describe('objects', () => {
249+
it('should return object literals', async () => {
250+
assert.deepEqual(await e('({ p })', { p: 'item_' }), { p: 'item_' });
251+
assert.deepEqual(await e('({ p: p })', { p: 'item_' }), { p: 'item_' });
252+
assert.deepEqual(await e('({ a: 1, b: 2 })'), { a: 1, b: 2 });
253+
assert.deepEqual(await e('({ a: 1, b: { c: 3 } })'), { a: 1, b: { c: 3 } });
254+
assert.deepEqual(await e('({ a: 1, b: { c: { d: 4 } } })'), { a: 1, b: { c: { d: 4 } } });
255+
});
256+
});
247257
});
248258

249259
describe('sync', () => {

test/async/expressions.js renamed to test/async/expressions.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('node:assert/strict');
44
const { evaluate: e } = require('../support');
55
const { generate } = require('escodegen');
66

7-
const opts = { functions: true, generate, strict: false };
7+
const opts = { functions: true, generate, strict: false, allowAwaitOutsideFunction: true };
88

99
describe('expressions', () => {
1010
describe('ObjectExpression', () => {
@@ -90,6 +90,11 @@ describe('expressions', () => {
9090
states: { a: 1, b: 2, c: 3, d: 4 }
9191
}, opts), ['a', 'b', 'c']);
9292

93+
// assert.deepEqual(await e('Object.keys(states.__proto__).filter(k => k != "d")', {
94+
// Object,
95+
// states: { a: 1, b: 2, c: 3, d: 4 }
96+
// }, opts), ['a', 'b', 'c']);
97+
9398
assert.deepEqual(await e('Object.keys(states).filter(k => k !== "c" && k !== "d")', {
9499
Object,
95100
states: { a: 1, b: 2, c: 3, d: 4 }
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/async/operators.js renamed to test/async/operators.test.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
'use strict';
22

33
const assert = require('node:assert/strict');
4-
const { evaluate: e } = require('../support');
4+
const { evaluate: e, expression } = require('../support');
5+
6+
describe('operators (async)', () => {
7+
describe('performance', () => {
8+
it('should evaluate 1,000 times', async () => {
9+
const start = Date.now();
10+
11+
for (let i = 0; i < 1000; i++) {
12+
await e('2 / 1 * 4 / 2');
13+
}
14+
15+
const end = Date.now();
16+
assert.ok(end - start < 100, 'Performance test failed');
17+
});
18+
19+
it('should pre-parse and evaluate 1,000 times', async () => {
20+
const start = Date.now();
21+
const exp = expression('2 / 1 * 4 / 2');
22+
23+
for (let i = 0; i < 1000; i++) {
24+
await exp('2 / 1 * 4 / 2');
25+
}
26+
27+
const end = Date.now();
28+
assert.ok(end - start < 100, 'Performance test failed');
29+
});
30+
});
531

6-
describe('operators', () => {
732
describe('grouping operators', () => {
833
it('should evaluate grouping operators', async () => {
934
assert.equal(await e('2 / 1 * 4 / 2'), 4);
@@ -188,8 +213,8 @@ describe('operators', () => {
188213
assert.equal(await e('v === undefined', { v: 1 }), false);
189214
assert.equal(await e('v === undefined', { v: null }), false);
190215
assert.equal(await e('v === undefined', { v: undefined }), true);
191-
assert.equal(await e('v === undefined', { v: 1, undefined: 1 }), false);
192216
assert.equal(await e('v === undefined'), true);
217+
assert.equal(await e('v === undefined', { v: 1, undefined: 1 }), false);
193218

194219
assert.equal(await e('a.b === undefined', { a: { b: null } }), false);
195220
assert.equal(await e('a.b === undefined', { a: { b: undefined } }), true);
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)