-
Notifications
You must be signed in to change notification settings - Fork 161
chore: improve test runtime by replacing ts-jest with swc #4336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
14cf591
Add @swc/jest dependency
dbjorge 7b897fa
Add @swc/jest configuration
dbjorge 91e69c3
Switch to an in-repo swc transformer that respects .swcrc
dbjorge 8e35f7c
Make transform path compatible with report-e2e-tests
dbjorge b031aac
Update snapshots whose function displayName changed
dbjorge 109acdb
Make our webextension-polyfill-ts setup compliant with import hoistin…
dbjorge a61202d
Replace collapsible-script-provider snapshot with one from swc
dbjorge a79bdf6
Add env to swcrc to allow it to use native async/await
dbjorge eb41b6f
Remove obsolete/unused processor
dbjorge 7316200
Regenerate snapshots with new env targetting codegen
dbjorge bfd0435
Move browserslist info to package.json
dbjorge 577a7f0
Fix collapsible-script-provider snapshot consistency between coverage…
dbjorge 61fca28
Drop references to ts-jest
dbjorge ba2ba0e
Update lockfile
dbjorge 4c76594
Omit .swcrc from copyright header check
dbjorge 79d6cd3
Add .swcrc to .prettierignore
dbjorge 3cb21fa
Fix grammar in comment
dbjorge dc1a44c
Revert "Remove obsolete/unused processor"
dbjorge 4c28bc4
Modify rule processor to ctor-inject suppressedMessages instead of us…
dbjorge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
.dependabot/ | ||
.github/ | ||
.prettierignore | ||
.swcrc | ||
.yarnrc | ||
.vs/ | ||
AppXManifest.xml | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true | ||
} | ||
}, | ||
"module": { | ||
"type": "commonjs", | ||
"noInterop": true | ||
}, | ||
"env": {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"./.dependabot", | ||
"./.git", | ||
"./.github", | ||
"./.swcrc", | ||
"./.vs", | ||
"./.vscode", | ||
"./dist", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
const { readFileSync } = require('fs'); | ||
const { join } = require('path'); | ||
const { transformSync } = require('@swc/core'); | ||
const { merge } = require('lodash'); | ||
|
||
// This file can be replaced by @swc/jest once https://github.com/swc-project/jest/issues/8 resolves | ||
|
||
const swcrcPath = join(__dirname, '..', '..', '..', '.swcrc'); | ||
const swcrc = JSON.parse(readFileSync(swcrcPath)); | ||
|
||
const jestTransformOverrides = { | ||
jsc: { | ||
transform: { | ||
hidden: { | ||
jest: true, | ||
}, | ||
}, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}; | ||
|
||
const baseTransformOptions = merge({}, swcrc, jestTransformOverrides); | ||
|
||
module.exports = { | ||
process: (src, path) => { | ||
if (/\.(t|j)sx?$/.test(path)) { | ||
const transformOptions = merge({}, baseTransformOptions, { | ||
filename: path, | ||
}); | ||
return transformSync(src, transformOptions); | ||
} | ||
return src; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
// webextension-polyfill errors on import if a global "chrome" variable is not defined | ||
const mockChromeGlobalRequired = (window as any).chrome == null; | ||
if (mockChromeGlobalRequired) { | ||
(window as any).chrome = { runtime: { id: 'mocked' } }; | ||
} | ||
|
||
// This must be "require" and not "import" to avoid swc hoisting the statement above the window | ||
// setup. See https://github.com/swc-project/swc/issues/1686 and | ||
// https://github.com/microsoft/TypeScript/pull/39764 | ||
require('webextension-polyfill-ts'); | ||
|
||
if (mockChromeGlobalRequired) { | ||
delete (window as any).chrome; | ||
} |
8 changes: 3 additions & 5 deletions
8
src/tests/unit/tests/common/browser-adapters/browser-adapter-factory.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Jest docs recommend implementing getCacheKey as well, although swc-jest transformer also doesn't seem to have it. Do you know if this would provide us any benefits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent question; I didn't look at the jest transformer docs at all to be honest, I was mostly adapting from swc-jest's transformer (it would be better to contribute .swcrc support back to them, but I'm blocked on legal approval to sign their CLA before I can do that). I'll investigate this after standup!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline; will investigate improvements to the transformer in a separate PR (ideally against the swc-project/jest repo directly)