Skip to content

Commit

Permalink
Change playwright scripts to use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
djahandarie committed Nov 9, 2023
1 parent b7d3cef commit c25e4c9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// @ts-check
const {defineConfig, devices} = require('@playwright/test');
import {defineConfig, devices} from '@playwright/test';

/**
* Read environment variables from file.
Expand All @@ -26,7 +26,7 @@ const {defineConfig, devices} = require('@playwright/test');
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
export default defineConfig({
testDir: './test/playwright',
snapshotPathTemplate: '{testDir}/__screenshots__/{testFilePath}/{arg}{ext}',
/* Maximum time one test can run for. */
Expand Down
12 changes: 6 additions & 6 deletions test/playwright/global.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const {test: setup} = require('@playwright/test');
const {ManifestUtil} = require('../../dev/manifest-util');
const {root} = require('./playwright-util');
const path = require('path');
const fs = require('fs');
import {test as setup} from '@playwright/test';
import fs from 'fs';
import path from 'path';
import {ManifestUtil} from '../../dev/manifest-util';
import {root} from './playwright-util';

const manifestPath = path.join(root, 'ext/manifest.json');
const copyManifestPath = path.join(root, 'ext/manifest-old.json');
Expand All @@ -29,4 +29,4 @@ setup('use test manifest', () => {
const variant = manifestUtil.getManifest('chrome-playwright');
fs.renameSync(manifestPath, copyManifestPath);
fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(variant).replace('$YOMITAN_VERSION', '0.0.0.0'));
});
});
10 changes: 5 additions & 5 deletions test/playwright/global.teardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const {test: teardown} = require('@playwright/test');
const {root} = require('./playwright-util');
const path = require('path');
const fs = require('fs');
import {test as teardown} from '@playwright/test';
import fs from 'fs';
import path from 'path';
import {root} from './playwright-util';

const manifestPath = path.join(root, 'ext/manifest.json');
const copyManifestPath = path.join(root, 'ext/manifest-old.json');

teardown('bring back original manifest', () => {
fs.renameSync(copyManifestPath, manifestPath);
});
});
18 changes: 9 additions & 9 deletions test/playwright/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const path = require('path');
const {
test,
import path from 'path';
import {createDictionaryArchive} from '../../dev/util';
import {
expect,
root,
mockModelFieldNames,
mockModelFieldsToAnkiValues,
expectedAddNoteBody,
mockAnkiRouteHandler,
mockModelFieldNames,
mockModelFieldsToAnkiValues,
root,
test,
writeToClipboardFromPage
} = require('./playwright-util');
const {createDictionaryArchive} = require('../../dev/util');
} from './playwright-util';

test.beforeEach(async ({context}) => {
// wait for the on-install welcome.html tab to load, which becomes the foreground tab
Expand Down Expand Up @@ -91,4 +91,4 @@ test('anki add', async ({context, page, extensionId}) => {
await page.locator('[data-mode="term-kanji"]').click();
const addNoteReqBody = await addNotePromise;
expect(addNoteReqBody).toMatchObject(expectedAddNoteBody);
});
});
10 changes: 6 additions & 4 deletions test/playwright/playwright-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const path = require('path');
const {test: base, chromium} = require('@playwright/test');
import {test as base, chromium} from '@playwright/test';
import path from 'path';
import {fileURLToPath} from 'url';

export const root = path.join(__dirname, '..', '..');
const dirname = path.dirname(fileURLToPath(import.meta.url));
export const root = path.join(dirname, '..', '..');

export const test = base.extend({
context: async ({ }, use) => {
Expand Down Expand Up @@ -106,4 +108,4 @@ const ankiRouteResponses = {
'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)
};
};
12 changes: 6 additions & 6 deletions test/playwright/visual.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const path = require('path');
import path from 'path';

const {
test,
import {
expect,
root
} = require('./playwright-util');
root,
test
} from './playwright-util';

test.beforeEach(async ({context}) => {
// wait for the on-install welcome.html tab to load, which becomes the foreground tab
Expand Down Expand Up @@ -97,4 +97,4 @@ test('visual', async ({page, extensionId}) => {
await screenshot(2, i, el, {x: 15, y: 15});
i++;
}
});
});

0 comments on commit c25e4c9

Please sign in to comment.