Skip to content

Commit

Permalink
Convert e2e unit tests to use Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Dec 5, 2024
1 parent cb4309f commit 2ca2cc2
Show file tree
Hide file tree
Showing 9 changed files with 2,090 additions and 2,103 deletions.
23 changes: 23 additions & 0 deletions e2e/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
};
59 changes: 0 additions & 59 deletions e2e/context-template.html

This file was deleted.

35 changes: 35 additions & 0 deletions e2e/fix-jsdom-environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import JSDOMEnvironment from 'jest-environment-jsdom';

/**
* JSDOMEnvironment patch to polyfill missing fetch with native
* Node fetch
*/
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
export default class FixJSDOMEnvironment extends JSDOMEnvironment {
constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
super(...args);

// FIXME https://github.com/jsdom/jsdom/issues/1724
this.global.fetch = fetch;
this.global.Headers = Headers;
this.global.Request = Request;
this.global.Response = Response;
}
}
22 changes: 11 additions & 11 deletions e2e/test-setup.js → e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2021 Google LLC
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,14 @@
* limitations under the License.
*/

const fs = require('fs');
import type { Config } from 'jest';

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

export default config;
97 changes: 0 additions & 97 deletions e2e/karma.conf.js

This file was deleted.

27 changes: 11 additions & 16 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "index.js",
"scripts": {
"setup": "node test-setup.js",
"test": "yarn setup && karma start --compat --modular",
"test:compat": "yarn setup && yarn karma start --compat",
"test:modular": "yarn setup && karma start --modular",
"test": "yarn jest",
"test:compat": "yarn jest tests/compat.test.ts",
"test:modular": "yarn jest tests/modular.test.ts",
"watch": "webpack --watch",
"build": "webpack",
"start:modular": "webpack serve --config-name modular",
Expand All @@ -18,22 +18,17 @@
"author": "",
"license": "ISC",
"dependencies": {
"firebase": "9.23.0"
"firebase": "11.0.2"
},
"devDependencies": {
"@babel/core": "7.24.4",
"@babel/preset-env": "7.24.4",
"@types/chai": "4.3.14",
"@types/mocha": "9.1.1",
"@babel/core": "7.26.0",
"@babel/preset-env": "7.26.0",
"@babel/preset-typescript": "7.26.0",
"@types/jest": "29.5.14",
"babel-jest": "29.7.0",
"babel-loader": "8.3.0",
"chai": "4.4.1",
"karma": "6.4.2",
"karma-chrome-launcher": "3.2.0",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.36",
"karma-typescript": "5.5.4",
"karma-typescript-es6-transform": "5.5.4",
"mocha": "9.2.2",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"typescript": "5.5.4",
"webpack": "5.76.0",
"webpack-cli": "5.1.4",
Expand Down
Loading

0 comments on commit 2ca2cc2

Please sign in to comment.