Skip to content

Commit

Permalink
test: Upgrade jest and fix environment
Browse files Browse the repository at this point in the history
  • Loading branch information
svsool committed Aug 6, 2022
1 parent 39d3af5 commit 525e777
Show file tree
Hide file tree
Showing 4 changed files with 432 additions and 866 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@
"eslint-plugin-unicorn": "^40.1.0",
"glob": "^8.0.3",
"husky": "^8.0.1",
"jest": "^27.5.1",
"jest-environment-vscode": "^1.0.0",
"jest": "28.1.3",
"jest-environment-node": "^28.1.3",
"jest-extended": "^3.0.1",
"lint-staged": "^13.0.3",
"mkdirp": "^1.0.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
const VscodeEnvironment = require('jest-environment-vscode');
const { TestEnvironment } = require('jest-environment-node');
const vscode = require('vscode');

class ExtendedVscodeEnvironment extends VscodeEnvironment {
class VsCodeEnvironment extends TestEnvironment {
async setup() {
await super.setup();

this.global.vscode = vscode;

// Expose RegExp otherwise document.getWordRangeAtPosition won't work as supposed.
// Implementation of getWordRangeAtPosition uses "instanceof RegExp" which returns false
// due to Jest running tests in the different vm context.
// See https://github.com/nodejs/node-v0.x-archive/issues/1277.
this.global.RegExp = RegExp;
}

async teardown() {
this.global.vscode = {};
await super.teardown();
}

runScript(script) {
return super.runScript(script);
}
}

module.exports = ExtendedVscodeEnvironment;
module.exports = VsCodeEnvironment;
2 changes: 1 addition & 1 deletion src/test/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function run(): Promise<void> {
transform: JSON.stringify({ '^.+\\.ts$': 'ts-jest' }),
runInBand: true,
testRegex: process.env.JEST_TEST_REGEX || '\\.(test|spec)\\.ts$',
testEnvironment: '<rootDir>/src/test/env/ExtendedVscodeEnvironment.js',
testEnvironment: '<rootDir>/src/test/env/VsCodeEnvironment.js',
setupFiles: ['<rootDir>/src/test/config/jestSetup.ts'],
setupFilesAfterEnv: ['jest-extended/all'],
globals: JSON.stringify({
Expand Down
Loading

0 comments on commit 525e777

Please sign in to comment.