Update typings for mocha (#752)
* Update typings for mocha This is includes an update of the lock file to the v2 format. It's a big change, but not much is happening here. I thought it best to keep it separate. * Fix globalSetup/teardown for mocha Updating the typings for mocha uncovered an error in how we were registering global setups and teardowns. When calling `mocha.globalSetup` or `mocha.globalTeardown`, any previously registered globals are overwritten. The workaround is to attach globals directly to the internal options object. This is a requirement because we are now registering globals in multiple files. Unfortunately, the typings for mocha do not permit this and I may need to fix them again.
This commit is contained in:
Родитель
be9084e83e
Коммит
6304fe0e30
|
@ -29,8 +29,7 @@ Here are a few things you can do that will increase the likelihood of your pull
|
|||
|
||||
## Setting up a local build
|
||||
|
||||
Make sure you have a fairly recent version of vscode (>1.32) and are using nodejs
|
||||
version >=v10.13.0. (Tested on v10.15.1 and v10.16.0).
|
||||
Make sure you have installed recent versions of vscode (>= v1.52), node (>=12.16), and npm (>= 7.5.2). Earlier versions will probably work, but we no longer test against them.
|
||||
|
||||
### Installing all packages
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ To see what has changed in the last few versions of the extension, see the [Chan
|
|||
* Provides an easy way to run queries from the large, open source repository of [CodeQL security queries](https://github.com/github/codeql).
|
||||
* Adds IntelliSense to support you writing and editing your own CodeQL query and library files.
|
||||
|
||||
|
||||
## Project goals and scope
|
||||
|
||||
This project will track new feature development in CodeQL and, whenever appropriate, bring that functionality to the Visual Studio Code experience.
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -771,7 +771,7 @@
|
|||
"@types/gulp-sourcemaps": "0.0.32",
|
||||
"@types/js-yaml": "^3.12.5",
|
||||
"@types/jszip": "~3.1.6",
|
||||
"@types/mocha": "^8.0.4",
|
||||
"@types/mocha": "^8.2.0",
|
||||
"@types/node": "^12.14.1",
|
||||
"@types/node-fetch": "~2.5.2",
|
||||
"@types/proxyquire": "~1.3.28",
|
||||
|
|
|
@ -16,14 +16,12 @@ export const DB_URL = 'https://github.com/github/vscode-codeql/files/5586722/sim
|
|||
export const dbLoc = path.join(fs.realpathSync(path.join(__dirname, '../../../')), 'build/tests/db.zip');
|
||||
export let storagePath: string;
|
||||
|
||||
// See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49860
|
||||
// Should be of type Mocha
|
||||
export default function(mocha: /*Mocha*/ any) {
|
||||
export default function(mocha: Mocha) {
|
||||
// create an extension storage location
|
||||
let removeStorage: tmp.DirResult['removeCallback'] | undefined;
|
||||
|
||||
mocha.globalSetup([
|
||||
// ensure the test database is downloaded
|
||||
// ensure the test database is downloaded
|
||||
(mocha.options as any).globalSetup.push(
|
||||
async () => {
|
||||
fs.mkdirpSync(path.dirname(dbLoc));
|
||||
if (!fs.existsSync(dbLoc)) {
|
||||
|
@ -44,14 +42,18 @@ export default function(mocha: /*Mocha*/ any) {
|
|||
fail('Failed to download test database: ' + e);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Set the CLI version here before activation to ensure we don't accidentally try to download a cli
|
||||
// Set the CLI version here before activation to ensure we don't accidentally try to download a cli
|
||||
(mocha.options as any).globalSetup.push(
|
||||
async () => {
|
||||
await workspace.getConfiguration().update('codeQL.cli.executablePath', process.env.CLI_PATH, ConfigurationTarget.Global);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Create the temp directory to be used as extension local storage.
|
||||
// Create the temp directory to be used as extension local storage.
|
||||
(mocha.options as any).globalSetup.push(
|
||||
() => {
|
||||
const dir = tmp.dirSync();
|
||||
storagePath = fs.realpathSync(dir.name);
|
||||
|
@ -61,10 +63,10 @@ export default function(mocha: /*Mocha*/ any) {
|
|||
|
||||
removeStorage = dir.removeCallback;
|
||||
}
|
||||
]);
|
||||
);
|
||||
|
||||
mocha.globalTeardown([
|
||||
// ensure etension is cleaned up.
|
||||
// ensure etension is cleaned up.
|
||||
(mocha.options as any).globalTeardown.push(
|
||||
async () => {
|
||||
const extension = await extensions.getExtension<CodeQLExtensionInterface | {}>('GitHub.vscode-codeql')!.activate();
|
||||
// This shuts down the extension and can only be run after all tests have completed.
|
||||
|
@ -72,10 +74,13 @@ export default function(mocha: /*Mocha*/ any) {
|
|||
if ('dispose' in extension) {
|
||||
extension.dispose();
|
||||
}
|
||||
},
|
||||
// ensure temp directory is cleaned up.
|
||||
}
|
||||
);
|
||||
|
||||
// ensure temp directory is cleaned up.
|
||||
(mocha.options as any).globalTeardown.push(
|
||||
() => {
|
||||
removeStorage?.();
|
||||
}
|
||||
]);
|
||||
);
|
||||
}
|
||||
|
|
|
@ -43,17 +43,17 @@ export async function runTestsInDirectory(testsRoot: string, useCli = false): Pr
|
|||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'bdd',
|
||||
color: true
|
||||
});
|
||||
color: true,
|
||||
globalSetup: [],
|
||||
globalTeardown: [],
|
||||
} as any);
|
||||
|
||||
// See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49860
|
||||
// Need to update to 8.2.0 of the typings.
|
||||
(mocha as any).globalSetup(() => {
|
||||
(mocha.options as any).globalSetup.push(
|
||||
// convert this function into an noop since it should not run during tests.
|
||||
// If it does run during tests, then it can cause some testing environments
|
||||
// to hang.
|
||||
(env as any).openExternal = () => { /**/ };
|
||||
});
|
||||
(env as any).openExternal = () => { /**/ }
|
||||
);
|
||||
|
||||
await ensureCli(useCli);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче