Skip to content

Commit

Permalink
chore: remove chai
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Jan 30, 2024
1 parent 46782c2 commit 5b218c7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 112 deletions.
24 changes: 17 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@
"name": "vscode-jest-tests",
"request": "launch",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": [
"--runInBand"
],
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"name": "Runtime Tests",
"request": "launch",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"env": {
"NODE_OPTIONS": "--experimental-vm-modules",
"TZ": "America/Los_Angeles"
},
"args": ["--runInBand", "--config", "test-runtime/jest-config.json"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"protocol": "inspector"
"port": 9229
}
]
}
2 changes: 1 addition & 1 deletion babel.config.js → babel.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Only used for jest
export default {
module.exports = {
presets: [
[
'@babel/preset-env',
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,13 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/chai": "^4.3.11",
"@types/d3": "^7.4.3",
"@types/jest": "^29.5.11",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"chai": "^5.0.3",
"cheerio": "^1.0.0-rc.12",
"conventional-changelog-cli": "^4.1.0",
"d3": "^7.8.5",
Expand Down
63 changes: 31 additions & 32 deletions test-runtime/translate.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable jest/expect-expect */
/* eslint-disable jest/valid-expect */

import {assert} from 'chai';
import {
bound,
brush,
Expand Down Expand Up @@ -34,7 +33,7 @@ describe('Translate interval selections at runtime', () => {

const hits = hitsMaster.interval;

for (const bind of [bound, unbound]) {
for (const bind of [bound, unbound] as const) {
describe(`${bind} intervals`, () => {
beforeAll(() => {
testRender = testRenderFn(page, `interval/translate/${bind}`);
Expand All @@ -45,25 +44,25 @@ describe('Translate interval selections at runtime', () => {

const assertExtent = {
[unbound]: {
x: ['isAbove', 'isBelow'],
y: ['isBelow', 'isAbove']
x: ['toBeGreaterThan', 'toBeLessThan'],
y: ['toBeLessThan', 'toBeGreaterThan']
},
[bound]: {
x: ['isBelow', 'isAbove'],
y: ['isAbove', 'isBelow']
x: ['toBeLessThan', 'toBeGreaterThan'],
y: ['toBeGreaterThan', 'toBeLessThan']
}
};
} as const;

it('should move back-and-forth', async () => {
for (let i = 0; i < hits.translate.length; i++) {
await embed(spec('unit', i, {type, ...binding}));
const drag = (await page.evaluate(brush('drag', i)))[0];
await testRender(`${i}-0`);
const translate = (await page.evaluate(brush('translate', i, null, bind === unbound)))[0];
assert[assertExtent[bind].x[i]](translate.values[0][0], drag.values[0][0]);
assert[assertExtent[bind].x[i]](translate.values[0][1], drag.values[0][1]);
assert[assertExtent[bind].y[i]](translate.values[1][0], drag.values[1][0]);
assert[assertExtent[bind].y[i]](translate.values[1][1], drag.values[1][1]);
expect(translate.values[0][0])[assertExtent[bind].x[i]](drag.values[0][0]);
expect(translate.values[0][1])[assertExtent[bind].x[i]](drag.values[0][1]);
expect(translate.values[1][0])[assertExtent[bind].y[i]](drag.values[1][0]);
expect(translate.values[1][1])[assertExtent[bind].y[i]](drag.values[1][1]);
await testRender(`${i}-1`);
}
});
Expand All @@ -85,8 +84,8 @@ describe('Translate interval selections at runtime', () => {
const drag = (await page.evaluate(brush('bins', i)))[0];
await testRender(`bins_${i}-0`);
const translate = (await page.evaluate(brush('bins_translate', i, null, bind === unbound)))[0];
assert[assertExtent[bind].y[i]](translate.values[0][0], drag.values[0][0]);
assert[assertExtent[bind].y[i]](translate.values[0][1], drag.values[0][1]);
expect(translate.values[0][0])[assertExtent[bind].y[i]](drag.values[0][0]);
expect(translate.values[0][1])[assertExtent[bind].y[i]](drag.values[0][1]);
await testRender(`bins_${i}-1`);
}
});
Expand All @@ -101,8 +100,8 @@ describe('Translate interval selections at runtime', () => {
const drag = toNumber(await page.evaluate(brush('drag', i)));
await testRender(`temporal_${i}-0`);
const translate = toNumber(await page.evaluate(brush('translate', i, null, bind === unbound)));
assert[assertExtent[bind].x[i]](translate[0], drag[0]);
assert[assertExtent[bind].x[i]](translate[1], drag[1]);
expect(translate[0])[assertExtent[bind].x[i]](drag[0]);
expect(translate[1])[assertExtent[bind].x[i]](drag[1]);
await testRender(`temporal_${i}-1`);
}
});
Expand All @@ -123,10 +122,10 @@ describe('Translate interval selections at runtime', () => {
const drag = (await page.evaluate(brush('drag', i)))[0];
await testRender(`logpow_${i}-0`);
const translate = (await page.evaluate(brush('translate', i, null, bind === unbound)))[0];
assert[assertExtent[bind].x[i]](translate.values[0][0], drag.values[0][0]);
assert[assertExtent[bind].x[i]](translate.values[0][1], drag.values[0][1]);
assert[assertExtent[bind].y[i]](translate.values[1][0], drag.values[1][0]);
assert[assertExtent[bind].y[i]](translate.values[1][1], drag.values[1][1]);
expect(translate.values[0][0])[assertExtent[bind].x[i]](drag.values[0][0]);
expect(translate.values[0][1])[assertExtent[bind].x[i]](drag.values[0][1]);
expect(translate.values[1][0])[assertExtent[bind].y[i]](drag.values[1][0]);
expect(translate.values[1][1])[assertExtent[bind].y[i]](drag.values[1][1]);
await testRender(`logpow_${i}-1`);
}
});
Expand All @@ -148,23 +147,23 @@ describe('Translate interval selections at runtime', () => {
const drag = (await page.evaluate(brush('drag', i)))[0];
await testRender(`ord_${i}-0`);
const translate = (await page.evaluate(brush('translate', i, null, true)))[0];
assert[assertExtent[bind].x[i]](translate.values[0][0], drag.values[0][0]);
assert[assertExtent[bind].x[i]](translate.values[0][1], drag.values[0][1]);
assert[assertExtent[bind].y[i]](translate.values[1][0], drag.values[1][0]);
assert[assertExtent[bind].y[i]](translate.values[1][1], drag.values[1][1]);
expect(translate.values[0][0])[assertExtent[bind].x[i]](drag.values[0][0]);
expect(translate.values[0][1])[assertExtent[bind].x[i]](drag.values[0][1]);
expect(translate.values[1][0])[assertExtent[bind].y[i]](drag.values[1][0]);
expect(translate.values[1][1])[assertExtent[bind].y[i]](drag.values[1][1]);
await testRender(`ord_${i}-1`);
}
});
} else {
for (const specType of compositeTypes) {
const assertExtents = {
repeat: {
x: ['isBelow', 'isBelow', 'isBelow'],
y: ['isAbove', 'isAbove', 'isAbove']
x: ['toBeLessThan', 'toBeLessThan', 'toBeLessThan'],
y: ['toBeGreaterThan', 'toBeGreaterThan', 'toBeGreaterThan']
},
facet: {
x: ['isBelow', 'isBelow', 'isBelow'],
y: ['isBelow', 'isAbove', 'isBelow']
x: ['toBeLessThan', 'toBeLessThan', 'toBeLessThan'],
y: ['toBeLessThan', 'toBeGreaterThan', 'toBeLessThan']
}
};
it(`should work with shared scales in ${specType} views`, async () => {
Expand All @@ -174,10 +173,10 @@ describe('Translate interval selections at runtime', () => {
const xscale = await page.evaluate('view._runtime.scales.x.value.domain()');
const yscale = await page.evaluate('view._runtime.scales.y.value.domain()');
const drag = (await page.evaluate(brush(specType, i, parent)))[0];
assert[assertExtents[specType].x[i]](drag.values[0][0], xscale[0], `iter: ${i}`);
assert[assertExtents[specType].x[i]](drag.values[0][1], xscale[1], `iter: ${i}`);
assert[assertExtents[specType].y[i]](drag.values[1][0], yscale[0], `iter: ${i}`);
assert[assertExtents[specType].y[i]](drag.values[1][1], yscale[1], `iter: ${i}`);
expect(drag.values[0][0])[assertExtents[specType].x[i]](xscale[0]);
expect(drag.values[0][1])[assertExtents[specType].x[i]](xscale[1]);
expect(drag.values[1][0])[assertExtents[specType].y[i]](yscale[0]);
expect(drag.values[1][1])[assertExtents[specType].y[i]](yscale[1]);
await testRender(`${specType}_${i}`);
}
});
Expand Down
43 changes: 21 additions & 22 deletions test-runtime/zoom.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable jest/expect-expect */

import {assert} from 'chai';
import {
bound,
brush,
Expand Down Expand Up @@ -42,7 +41,7 @@ describe('Zoom interval selections at runtime', () => {
await page.close();
});

for (const bind of [bound, unbound]) {
for (const bind of [bound, unbound] as const) {
describe(`Zoom ${bind} interval selections at runtime`, () => {
beforeAll(() => {
testRender = testRenderFn(page, `interval/zoom/${bind}`);
Expand All @@ -53,9 +52,9 @@ describe('Zoom interval selections at runtime', () => {
const cmp = (a: number, b: number) => a - b;

const assertExtent = {
in: ['isAtLeast', 'isAtMost'],
out: ['isAtMost', 'isAtLeast']
};
in: ['toBeGreaterThanOrEqual', 'toBeLessThanOrEqual'],
out: ['toBeLessThanOrEqual', 'toBeGreaterThanOrEqual']
} as const;

async function setup(brushKey: string, idx: number, encodings: string[], parent?: string) {
const inOut: InOut = idx % 2 ? 'out' : 'in';
Expand Down Expand Up @@ -84,10 +83,10 @@ describe('Zoom interval selections at runtime', () => {
const xnew = zoomed.values[0].sort(cmp);
const ynew = zoomed.values[1].sort(cmp);
await testRender(`${inOut}-1`);
assert[assertExtent[inOut][0]](xnew[0], xold[0]);
assert[assertExtent[inOut][1]](xnew[1], xold[1]);
assert[assertExtent[inOut][0]](ynew[0], yold[0]);
assert[assertExtent[inOut][1]](ynew[1], yold[1]);
expect(xnew[0])[assertExtent[inOut][0]](xold[0]);
expect(xnew[1])[assertExtent[inOut][1]](xold[1]);
expect(ynew[0])[assertExtent[inOut][0]](yold[0]);
expect(ynew[1])[assertExtent[inOut][1]](yold[1]);
}
});

Expand All @@ -112,8 +111,8 @@ describe('Zoom interval selections at runtime', () => {

const zoomed = (await page.evaluate(zoom('bins', i, inOut, null, bind === unbound)))[0];
const ynew = zoomed.values[0].sort(cmp);
assert[assertExtent[inOut][0]](ynew[0], yold[0]);
assert[assertExtent[inOut][1]](ynew[1], yold[1]);
expect(ynew[0])[assertExtent[inOut][0]](yold[0]);
expect(ynew[1])[assertExtent[inOut][1]](yold[1]);
await testRender(`bins_${inOut}-1`);
}
});
Expand All @@ -129,8 +128,8 @@ describe('Zoom interval selections at runtime', () => {

const zoomed = (await page.evaluate(zoom('zoom', i, inOut, null, bind === unbound)))[0];
const xnew = zoomed.values[0].sort(cmp);
assert[assertExtent[inOut][0]](+xnew[0], +new Date(xold[0]));
assert[assertExtent[inOut][1]](+xnew[1], +new Date(xold[1]));
expect(+xnew[0])[assertExtent[inOut][0]](+new Date(xold[0]));
expect(+xnew[1])[assertExtent[inOut][1]](+new Date(xold[1]));
await testRender(`temporal_${inOut}-1`);
}
});
Expand All @@ -154,10 +153,10 @@ describe('Zoom interval selections at runtime', () => {
const zoomed = (await page.evaluate(zoom('zoom', i, inOut, null, bind === unbound)))[0];
const xnew = zoomed.values[0].sort(cmp);
const ynew = zoomed.values[1].sort(cmp);
assert[assertExtent[inOut][0]](xnew[0], xold[0]);
assert[assertExtent[inOut][1]](xnew[1], xold[1]);
assert[assertExtent[inOut][0]](ynew[0], yold[0]);
assert[assertExtent[inOut][1]](ynew[1], yold[1]);
expect(xnew[0])[assertExtent[inOut][0]](xold[0]);
expect(xnew[1])[assertExtent[inOut][1]](xold[1]);
expect(ynew[0])[assertExtent[inOut][0]](yold[0]);
expect(ynew[1])[assertExtent[inOut][1]](yold[1]);
await testRender(`logpow_${inOut}-1`);
}
});
Expand Down Expand Up @@ -201,13 +200,13 @@ describe('Zoom interval selections at runtime', () => {
await embed(spec(specType, 0, {type, ...binding}, {resolve: {scale: {x: 'shared', y: 'shared'}}}));
const parent = parentSelector(specType, i);
const {inOut, xold, yold} = await setup(specType, i, ['x', 'y'], parent);
const zoomed = (await page.evaluate(zoom('bins', i, inOut, null, bind === unbound)))[0];
const zoomed = (await page.evaluate(zoom('bins', i, inOut, null, false /* bind === unbound */)))[0];
const xnew = zoomed.values[0].sort(cmp);
const ynew = zoomed.values[1].sort(cmp);
assert[assertExtent[inOut][0]](xnew[0], xold[0]);
assert[assertExtent[inOut][1]](xnew[1], xold[1]);
assert[assertExtent[inOut][0]](ynew[0], yold[0]);
assert[assertExtent[inOut][1]](ynew[1], yold[1]);
expect(xnew[0])[assertExtent[inOut][0]](xold[0]);
expect(xnew[1])[assertExtent[inOut][1]](xold[1]);
expect(ynew[0])[assertExtent[inOut][0]](yold[0]);
expect(ynew[1])[assertExtent[inOut][1]](yold[1]);
await testRender(`${specType}_${inOut}`);
}
});
Expand Down
Loading

0 comments on commit 5b218c7

Please sign in to comment.