Skip to content

Commit 1e8edb7

Browse files
authored
Convert e2e unit tests to use Jest (#8666)
1 parent cb4309f commit 1e8edb7

9 files changed

+2090
-2103
lines changed

e2e/babel.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
presets: [
20+
['@babel/preset-env', { targets: { node: 'current' } }],
21+
'@babel/preset-typescript'
22+
]
23+
};

e2e/context-template.html

Lines changed: 0 additions & 59 deletions
This file was deleted.

e2e/fix-jsdom-environment.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import JSDOMEnvironment from 'jest-environment-jsdom';
19+
20+
/**
21+
* JSDOMEnvironment patch to polyfill missing fetch with native
22+
* Node fetch
23+
*/
24+
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
25+
export default class FixJSDOMEnvironment extends JSDOMEnvironment {
26+
constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
27+
super(...args);
28+
29+
// FIXME https://github.com/jsdom/jsdom/issues/1724
30+
this.global.fetch = fetch;
31+
this.global.Headers = Headers;
32+
this.global.Request = Request;
33+
this.global.Response = Response;
34+
}
35+
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2021 Google LLC
3+
* Copyright 2024 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -15,14 +15,14 @@
1515
* limitations under the License.
1616
*/
1717

18-
const fs = require('fs');
18+
import type { Config } from 'jest';
1919

20-
const contextHtml = fs.readFileSync('./context-template.html', 'utf8');
21-
fs.writeFileSync(
22-
'./context.html',
23-
// Include single quotes so it doesn't replace the comment.
24-
contextHtml.replace(
25-
"'APP_CHECK_DEBUG_TOKEN'",
26-
`'${process.env.APP_CHECK_DEBUG_TOKEN}'`
27-
)
28-
);
20+
const config: Config = {
21+
verbose: true,
22+
testEnvironment: './fix-jsdom-environment.ts',
23+
globals: {
24+
FIREBASE_APPCHECK_DEBUG_TOKEN: process.env.APP_CHECK_DEBUG_TOKEN
25+
}
26+
};
27+
28+
export default config;

e2e/karma.conf.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

e2e/package.json

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"main": "index.js",
66
"scripts": {
77
"setup": "node test-setup.js",
8-
"test": "yarn setup && karma start --compat --modular",
9-
"test:compat": "yarn setup && yarn karma start --compat",
10-
"test:modular": "yarn setup && karma start --modular",
8+
"test": "yarn jest",
9+
"test:compat": "yarn jest tests/compat.test.ts",
10+
"test:modular": "yarn jest tests/modular.test.ts",
1111
"watch": "webpack --watch",
1212
"build": "webpack",
1313
"start:modular": "webpack serve --config-name modular",
@@ -18,22 +18,17 @@
1818
"author": "",
1919
"license": "ISC",
2020
"dependencies": {
21-
"firebase": "9.23.0"
21+
"firebase": "11.0.2"
2222
},
2323
"devDependencies": {
24-
"@babel/core": "7.24.4",
25-
"@babel/preset-env": "7.24.4",
26-
"@types/chai": "4.3.14",
27-
"@types/mocha": "9.1.1",
24+
"@babel/core": "7.26.0",
25+
"@babel/preset-env": "7.26.0",
26+
"@babel/preset-typescript": "7.26.0",
27+
"@types/jest": "29.5.14",
28+
"babel-jest": "29.7.0",
2829
"babel-loader": "8.3.0",
29-
"chai": "4.4.1",
30-
"karma": "6.4.2",
31-
"karma-chrome-launcher": "3.2.0",
32-
"karma-mocha": "2.0.1",
33-
"karma-spec-reporter": "0.0.36",
34-
"karma-typescript": "5.5.4",
35-
"karma-typescript-es6-transform": "5.5.4",
36-
"mocha": "9.2.2",
30+
"jest": "29.7.0",
31+
"jest-environment-jsdom": "29.7.0",
3732
"typescript": "5.5.4",
3833
"webpack": "5.76.0",
3934
"webpack-cli": "5.1.4",

0 commit comments

Comments
 (0)