fix: tentatively fix flaky tests
In CI the tests sometimes fail with the following error:
`ReferenceError: exports is not defined`.[1]
This commit changes the ts-node Jest preset to transpile code into
CommonJS instead of using ESM, since the latter is considered
experimental. It is unknown whether this will fix the issue in the CI,
but it might help.
Due to this change, this commit also migrates a Javascript test to
Typescript.
[1]: https://zuul.corp.avm99963.com/t/gerrit/build/08e3a3723c03477cbd3f7c63d0568be9
Change-Id: I31f4e0fa6ec5d28ce97fae108e51eccc412c4535
diff --git a/Makefile b/Makefile
index 5383c36..a2c4b31 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
.PHONY: node_deps clean_dist deps clean_deps lit_localize_extract lit_localize_build lit_localize_all serve_chromium_mv3 serve_gecko release release_chromium_stable release_chromium_beta release_chromium_canary release_gecko_stable build_test_extension clean_releases test clean trigger_nightly_build
WEBPACK := ./node_modules/webpack-cli/bin/cli.js
-JEST := node --experimental-vm-modules ./node_modules/jest/bin/jest.js
+JEST := node ./node_modules/jest/bin/jest.js
RELEASE_SCRIPT := bash tools/release.bash
grpc_proto_gen:
diff --git a/jest.config.js b/jest.config.js
index b394077..c468c76 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -4,7 +4,7 @@
*/
module.exports = {
- preset : 'ts-jest/presets/js-with-ts-esm',
+ preset : 'ts-jest/presets/js-with-ts',
moduleFileExtensions : ['js', 'mjs', 'ts'],
testRegex : '(/__tests__/.*|(\\.|/)(test|spec))\\.m?[jt]sx?$',
coverageProvider : 'v8',
diff --git a/roles/test/tasks/main.yaml b/roles/test/tasks/main.yaml
index 8430fc7..80d0848 100644
--- a/roles/test/tasks/main.yaml
+++ b/roles/test/tasks/main.yaml
@@ -2,7 +2,7 @@
shell:
cmd: |
set -euxo pipefail
- node --experimental-vm-modules ./node_modules/jest/bin/jest.js --ci |& tee out/jest-log.txt
+ node ./node_modules/jest/bin/jest.js --ci |& tee out/jest-log.txt
chdir: "{{ zuul.project.src_dir }}"
executable: /bin/bash
changed_when: false
diff --git a/src/common/protojs.test.mjs b/src/common/protojs.test.mjs
deleted file mode 100644
index b5ee44c..0000000
--- a/src/common/protojs.test.mjs
+++ /dev/null
@@ -1,148 +0,0 @@
-/* eslint-disable no-sparse-arrays */
-import * as protojs from './protojs.js';
-
-const objectLike1 = {
- '2': [1, 2, 3],
-};
-
-const arrayLike1 = [
- undefined,
- [1, 2, 3],
-];
-
-const rObjectLike1 = [
- ,
- undefined,
- [, 1, 2, 3],
-];
-
-const objectLike2 = {
- '1': {
- '1': 12,
- '2': [
- {
- '6': [false, false, false],
- '7': {
- '1': false,
- '2': 'Hola',
- },
- },
- {
- '6': [true, true, false],
- '7': {
- '1': false,
- '2': 'Test',
- },
- },
- {
- '6': [],
- '7': {
- '1': true,
- '2': 'Bye',
- },
- },
- ],
- '3': 1663,
- },
-};
-
-const arrayLike2 = [[
- 12,
- [
- [
- undefined, undefined, undefined, undefined, undefined,
- [false, false, false],
- [
- false,
- 'Hola',
- ]
- ],
- [
- undefined, undefined, undefined, undefined, undefined,
- [true, true, false],
- [
- false,
- 'Test',
- ]
- ],
- [
- undefined, undefined, undefined, undefined, undefined, [],
- [
- true,
- 'Bye',
- ]
- ],
- ],
- 1663,
-]];
-
-const rObjectLike2 = [, [
- ,
- 12,
- [
- ,
- [
- , undefined, undefined, undefined, undefined, undefined,
- [, false, false, false],
- [
- ,
- false,
- 'Hola',
- ]
- ],
- [
- , undefined, undefined, undefined, undefined, undefined,
- [, true, true, false],
- [
- ,
- false,
- 'Test',
- ]
- ],
- [
- , undefined, undefined, undefined, undefined, undefined, [],
- [
- ,
- true,
- 'Bye',
- ]
- ],
- ],
- 1663,
-]];
-
-test('can convert object-like to array-like', () => {
- // [ object-like input, array-like verified output ]
- const entries = [
- [objectLike1, arrayLike1],
- [rObjectLike1, arrayLike1],
- [objectLike2, arrayLike2],
- [rObjectLike2, arrayLike2],
- ];
-
- entries.forEach(([input, verifiedOutput]) => {
- const converted = protojs.inverseCorrectArrayKeys(input);
- expect(converted).toStrictEqual(verifiedOutput);
- });
-});
-
-test('can convert array-like to object-like', () => {
- // [ array-like input, object-like verified output ]
- const entries = [
- [arrayLike1, rObjectLike1],
- [arrayLike2, rObjectLike2],
- ];
-
- entries.forEach(([input, verifiedOutput]) => {
- const converted = protojs.correctArrayKeys(input);
- expect(converted).toStrictEqual(verifiedOutput);
- });
-});
-
-test('empty object can be converted to array-like form', () => {
- const object = {
- 1: {},
- };
- const converted = protojs.inverseCorrectArrayKeys(object);
- expect(converted).toStrictEqual([[]]);
-});
diff --git a/src/common/protojs.test.ts b/src/common/protojs.test.ts
new file mode 100644
index 0000000..bc12854
--- /dev/null
+++ b/src/common/protojs.test.ts
@@ -0,0 +1,155 @@
+/* eslint-disable no-sparse-arrays */
+import { expect, test } from '@jest/globals';
+import * as protojs from './protojs.js';
+
+const objectLike1 = {
+ '2': [1, 2, 3],
+};
+
+const arrayLike1 = [undefined, [1, 2, 3]];
+
+const rObjectLike1 = [, undefined, [, 1, 2, 3]];
+
+const objectLike2 = {
+ '1': {
+ '1': 12,
+ '2': [
+ {
+ '6': [false, false, false],
+ '7': {
+ '1': false,
+ '2': 'Hola',
+ },
+ },
+ {
+ '6': [true, true, false],
+ '7': {
+ '1': false,
+ '2': 'Test',
+ },
+ },
+ {
+ '6': [],
+ '7': {
+ '1': true,
+ '2': 'Bye',
+ },
+ },
+ ],
+ '3': 1663,
+ },
+};
+
+const arrayLike2 = [
+ [
+ 12,
+ [
+ [
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ [false, false, false],
+ [false, 'Hola'],
+ ],
+ [
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ [true, true, false],
+ [false, 'Test'],
+ ],
+ [
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ [],
+ [true, 'Bye'],
+ ],
+ ],
+ 1663,
+ ],
+];
+
+const rObjectLike2 = [
+ ,
+ [
+ ,
+ 12,
+ [
+ ,
+ [
+ ,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ [, false, false, false],
+ [, false, 'Hola'],
+ ],
+ [
+ ,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ [, true, true, false],
+ [, false, 'Test'],
+ ],
+ [
+ ,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ [],
+ [, true, 'Bye'],
+ ],
+ ],
+ 1663,
+ ],
+];
+
+test('can convert object-like to array-like', () => {
+ // [ object-like input, array-like verified output ]
+ const entries = [
+ [objectLike1, arrayLike1],
+ [rObjectLike1, arrayLike1],
+ [objectLike2, arrayLike2],
+ [rObjectLike2, arrayLike2],
+ ];
+
+ entries.forEach(([input, verifiedOutput]) => {
+ const converted = protojs.inverseCorrectArrayKeys(input);
+ expect(converted).toStrictEqual(verifiedOutput);
+ });
+});
+
+test('can convert array-like to object-like', () => {
+ // [ array-like input, object-like verified output ]
+ const entries = [
+ [arrayLike1, rObjectLike1],
+ [arrayLike2, rObjectLike2],
+ ];
+
+ entries.forEach(([input, verifiedOutput]) => {
+ const converted = protojs.correctArrayKeys(input);
+ expect(converted).toStrictEqual(verifiedOutput);
+ });
+});
+
+test('empty object can be converted to array-like form', () => {
+ const object = {
+ 1: {},
+ };
+ const converted = protojs.inverseCorrectArrayKeys(object);
+ expect(converted).toStrictEqual([[]]);
+});