summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core.test.js12
-rw-r--r--test/fixtures/dom-test.js11
-rw-r--r--test/hotkey-util.test.js2
-rw-r--r--test/json-schema.test.js18
-rw-r--r--test/playwright/playwright-util.js57
5 files changed, 62 insertions, 38 deletions
diff --git a/test/core.test.js b/test/core.test.js
index 0ddcc2d1..7e19d04d 100644
--- a/test/core.test.js
+++ b/test/core.test.js
@@ -269,8 +269,16 @@ function testDeepEqual() {
/** @type {import('test/core').DeepEqualTestData} */
const recursiveTestsData = [
{
- value1: (() => { const x = {}; x.x = x; return x; })(),
- value2: (() => { const x = {}; x.x = x; return x; })(),
+ value1: (() => {
+ const x = {};
+ x.x = x;
+ return x;
+ })(),
+ value2: (() => {
+ const x = {};
+ x.x = x;
+ return x;
+ })(),
expected: false
}
];
diff --git a/test/fixtures/dom-test.js b/test/fixtures/dom-test.js
index a0a17127..578b1324 100644
--- a/test/fixtures/dom-test.js
+++ b/test/fixtures/dom-test.js
@@ -43,10 +43,13 @@ function prepareWindow(window) {
export async function setupDomTest(htmlFilePath) {
const html = typeof htmlFilePath === 'string' ? fs.readFileSync(htmlFilePath, {encoding: 'utf8'}) : '<!DOCTYPE html>';
const env = builtinEnvironments.jsdom;
- const {teardown} = await env.setup(global, {jsdom: {html}});
+ const environment = await env.setup(global, {jsdom: {html}});
const window = /** @type {import('jsdom').DOMWindow} */ (/** @type {unknown} */ (global.window));
prepareWindow(window);
- return {window, teardown};
+ return {
+ window,
+ teardown: (global) => environment.teardown(global)
+ };
}
/**
@@ -59,13 +62,13 @@ export function createDomTest(htmlFilePath) {
// eslint-disable-next-line no-empty-pattern
window: async ({}, use) => {
const env = builtinEnvironments.jsdom;
- const {teardown} = await env.setup(global, {jsdom: {html}});
+ const environment = await env.setup(global, {jsdom: {html}});
const window = /** @type {import('jsdom').DOMWindow} */ (/** @type {unknown} */ (global.window));
prepareWindow(window);
try {
await use(window);
} finally {
- teardown(global);
+ environment.teardown(global);
}
}
});
diff --git a/test/hotkey-util.test.js b/test/hotkey-util.test.js
index bf1124a5..01a2b536 100644
--- a/test/hotkey-util.test.js
+++ b/test/hotkey-util.test.js
@@ -160,7 +160,7 @@ function testSortModifiers() {
const hotkeyUtil = new HotkeyUtil();
for (const {modifiers, expected} of data) {
- test(`[${modifiers}] -> [${expected}]`, () => {
+ test(`[${modifiers.join(',')}] -> [${expected.join(',')}]`, () => {
const modifiers2 = hotkeyUtil.sortModifiers(modifiers);
expect(modifiers2).toStrictEqual(modifiers);
expect(modifiers2).toStrictEqual(expected);
diff --git a/test/json-schema.test.js b/test/json-schema.test.js
index ab2c0c65..af4b7acd 100644
--- a/test/json-schema.test.js
+++ b/test/json-schema.test.js
@@ -520,7 +520,7 @@ function testValidate2() {
/* eslint-enable @stylistic/no-multi-spaces */
describe.each(data)('Schema %#', ({schema, inputs}) => {
- test.each(inputs)(`schemaValidate(${schema}, $value) -> $expected`, ({expected, value}) => {
+ test.each(inputs)(`schemaValidate(${JSON.stringify(schema)}, $value) -> $expected`, ({expected, value}) => {
const actual = schemaValidate(schema, value);
expect(actual).toStrictEqual(expected);
});
@@ -878,7 +878,7 @@ function testGetValidValueOrDefault1() {
];
describe.each(data)('Schema %#', ({schema, inputs}) => {
- test.each(inputs)(`getValidValueOrDefault(${schema}, %o) -> %o`, (value, expected) => {
+ test.each(inputs)(`getValidValueOrDefault(${JSON.stringify(schema)}, %o) -> %o`, (value, expected) => {
const actual = getValidValueOrDefault(schema, value);
expect(actual).toStrictEqual(expected);
});
@@ -985,11 +985,15 @@ function testProxy1() {
{error: true, value: ['default'], action: (value) => { value[0] = null; }},
{error: false, value: ['default'], action: (value) => { delete value[0]; }},
{error: false, value: ['default'], action: (value) => { value[1] = 'string'; }},
- {error: false, value: ['default'], action: (value) => {
- value[1] = 'string';
- if (value.length !== 2) { throw new Error(`Invalid length; expected=2; actual=${value.length}`); }
- if (typeof value.push !== 'function') { throw new Error(`Invalid push; expected=function; actual=${typeof value.push}`); }
- }}
+ {
+ error: false,
+ value: ['default'],
+ action: (value) => {
+ value[1] = 'string';
+ if (value.length !== 2) { throw new Error(`Invalid length; expected=2; actual=${value.length}`); }
+ if (typeof value.push !== 'function') { throw new Error(`Invalid push; expected=function; actual=${typeof value.push}`); }
+ }
+ }
]
},
diff --git a/test/playwright/playwright-util.js b/test/playwright/playwright-util.js
index bf171251..b364c80b 100644
--- a/test/playwright/playwright-util.js
+++ b/test/playwright/playwright-util.js
@@ -20,6 +20,7 @@ import path from 'path';
import {fileURLToPath} from 'url';
const dirname = path.dirname(fileURLToPath(import.meta.url));
+
export const root = path.join(dirname, '..', '..');
export const test = base.extend({
@@ -47,6 +48,7 @@ export const test = base.extend({
await use(extensionId);
}
});
+
export const expect = test.expect;
export const mockModelFieldNames = [
@@ -58,10 +60,10 @@ export const mockModelFieldNames = [
/** @type {{[key: string]: string|undefined}} */
export const mockModelFieldsToAnkiValues = {
- 'Word': '{expression}',
- 'Reading': '{furigana-plain}',
- 'Sentence': '{clipboard-text}',
- 'Audio': '{audio}'
+ Word: '{expression}',
+ Reading: '{furigana-plain}',
+ Sentence: '{clipboard-text}',
+ Audio: '{audio}'
};
/**
@@ -87,23 +89,30 @@ export const writeToClipboardFromPage = async (page, text) => {
};
export const expectedAddNoteBody = {
- 'action': 'addNote',
- 'params':
- {
- 'note': {
- 'fields': {
- 'Word': '読む', 'Reading': '読[よ]む', 'Audio': '[sound:mock_audio.mp3]', 'Sentence': '読むの例文'
+ version: 2,
+ action: 'addNote',
+ params: {
+ note: {
+ fields: {
+ Word: '読む',
+ Reading: '読[よ]む',
+ Audio: '[sound:mock_audio.mp3]',
+ Sentence: '読むの例文'
},
- 'tags': ['yomitan'],
- 'deckName': 'Mock Deck',
- 'modelName': 'Mock Model',
- 'options': {
- 'allowDuplicate': false, 'duplicateScope': 'collection', 'duplicateScopeOptions': {
- 'deckName': null, 'checkChildren': false, 'checkAllModels': false
+ tags: ['yomitan'],
+ deckName: 'Mock Deck',
+ modelName: 'Mock Model',
+ options: {
+ allowDuplicate: false,
+ duplicateScope: 'collection',
+ duplicateScopeOptions: {
+ deckName: null,
+ checkChildren: false,
+ checkAllModels: false
}
}
}
- }, 'version': 2
+ }
};
const baseAnkiResp = {
@@ -113,11 +122,11 @@ const baseAnkiResp = {
/** @type {{[key: string]: import('core').SerializableObject}} */
const ankiRouteResponses = {
- 'version': Object.assign({body: JSON.stringify(6)}, baseAnkiResp),
- 'deckNames': Object.assign({body: JSON.stringify(['Mock Deck'])}, baseAnkiResp),
- 'modelNames': Object.assign({body: JSON.stringify(['Mock Model'])}, baseAnkiResp),
- 'modelFieldNames': Object.assign({body: JSON.stringify(mockModelFieldNames)}, baseAnkiResp),
- 'canAddNotes': Object.assign({body: JSON.stringify([true, true])}, baseAnkiResp),
- 'storeMediaFile': Object.assign({body: JSON.stringify('mock_audio.mp3')}, baseAnkiResp),
- 'addNote': Object.assign({body: JSON.stringify(102312488912)}, baseAnkiResp)
+ version: Object.assign({body: JSON.stringify(6)}, baseAnkiResp),
+ deckNames: Object.assign({body: JSON.stringify(['Mock Deck'])}, baseAnkiResp),
+ modelNames: Object.assign({body: JSON.stringify(['Mock Model'])}, baseAnkiResp),
+ modelFieldNames: Object.assign({body: JSON.stringify(mockModelFieldNames)}, baseAnkiResp),
+ canAddNotes: Object.assign({body: JSON.stringify([true, true])}, baseAnkiResp),
+ storeMediaFile: Object.assign({body: JSON.stringify('mock_audio.mp3')}, baseAnkiResp),
+ addNote: Object.assign({body: JSON.stringify(102312488912)}, baseAnkiResp)
};