Skip to content

Commit

Permalink
Merge pull request FreezingMoon#2197 from andretchen0/queue-ts
Browse files Browse the repository at this point in the history
Add TS/DOM support for Jest FreezingMoon#997 FreezingMoon#1969
  • Loading branch information
DreadKnight authored Apr 11, 2023
2 parents 09e34ea + 6d1af5c commit 5bb95a8
Show file tree
Hide file tree
Showing 9 changed files with 722 additions and 82 deletions.
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

31 changes: 31 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = (api) => {
// Source: https://www.wisdomgeek.com/development/web-development/how-to-setup-jest-typescript-babel-webpack-project/
// Testing if babel is being run in test mode
const isTest = api.env('test');
/**
* Cache the returned value forever and don't call this function again. This is the default behavior but since we
* are reading the env value above, we need to explicitly set it after we are done doing that, else we get a
* caching was left unconfigured error.
*/
api.cache(true);
return {
plugins: ['@babel/plugin-transform-runtime'],
presets: [
// Enabling Babel to understand TypeScript
'@babel/preset-typescript',
[
// Allows smart transpilation according to target environments
'@babel/preset-env',
{
/**
* Specifying what module type should the output be in.
* For test cases, we transpile all the way down to commonjs since jest does not understand TypeScript.
* For all other cases, we don't transform since we want Webpack to do that in order for it to do
* dead code elimination (tree shaking) and intelligently select what all to add to the bundle.
*/
modules: isTest ? 'commonjs' : false,
},
],
],
};
};
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module.exports = {
// snapshotSerializers: [],

// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",
testEnvironment: 'jest-environment-jsdom',

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
Expand Down
Loading

0 comments on commit 5bb95a8

Please sign in to comment.