Skip to content

Commit c31635f

Browse files
authored
Merge pull request #1782 from github/jest-migration/no-workspace
Migrate no-workspace integration tests to Jest
2 parents cc869da + e26e111 commit c31635f

38 files changed

Lines changed: 1881 additions & 1745 deletions

extensions/ql-vscode/jest.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* https://jestjs.io/docs/configuration
44
*/
55

6+
/** @type {import('@jest/types').Config.InitialOptions} */
67
module.exports = {
7-
projects: ["<rootDir>/src/view", "<rootDir>/test"],
8+
projects: [
9+
"<rootDir>/src/view",
10+
"<rootDir>/test",
11+
"<rootDir>/out/vscode-tests/no-workspace",
12+
],
813
};

extensions/ql-vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,8 @@
12721272
"test": "npm-run-all -p test:*",
12731273
"test:unit": "jest --projects test",
12741274
"test:view": "jest --projects src/view",
1275-
"integration": "node ./out/vscode-tests/run-integration-tests.js no-workspace,minimal-workspace",
1276-
"integration:no-workspace": "node ./out/vscode-tests/run-integration-tests.js no-workspace",
1275+
"integration": "npm-run-all integration:*",
1276+
"integration:no-workspace": "jest --projects out/vscode-tests/no-workspace",
12771277
"integration:minimal-workspace": "node ./out/vscode-tests/run-integration-tests.js minimal-workspace",
12781278
"cli-integration": "node ./out/vscode-tests/run-integration-tests.js cli-integration",
12791279
"update-vscode": "node ./node_modules/vscode/bin/install",

extensions/ql-vscode/src/vscode-tests/factories/local-queries/local-query-history-item.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export function createMockLocalQueryInfo({
6666
}
6767

6868
export function createMockQueryWithResults({
69-
sandbox = undefined,
7069
didRunSuccessfully = true,
7170
hasInterpretedResults = true,
7271
hasMetadata = undefined,
@@ -76,16 +75,8 @@ export function createMockQueryWithResults({
7675
hasInterpretedResults?: boolean;
7776
hasMetadata?: boolean;
7877
}): QueryWithResults {
79-
const dispose = sandbox
80-
? sandbox.spy()
81-
: () => {
82-
/**/
83-
};
84-
const deleteQuery = sandbox
85-
? sandbox.stub()
86-
: () => {
87-
/**/
88-
};
78+
const dispose = jest.fn();
79+
const deleteQuery = jest.fn();
8980
const metadata = hasMetadata
9081
? ({ name: "query-name" } as QueryMetadata)
9182
: undefined;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as path from "path";
2+
import * as tmp from "tmp-promise";
3+
import { RunnerOptions } from "jest-runner-vscode";
4+
5+
export const tmpDir = tmp.dirSync({ unsafeCleanup: true });
6+
7+
export const rootDir = path.resolve(__dirname, "../..");
8+
9+
const config: RunnerOptions = {
10+
version: "stable",
11+
launchArgs: [
12+
"--disable-extensions",
13+
"--disable-gpu",
14+
"--user-data-dir=" + path.join(tmpDir.name, "user-data"),
15+
],
16+
extensionDevelopmentPath: rootDir,
17+
};
18+
19+
export default config;
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
import type { Config } from "jest";
2+
3+
/*
4+
* For a detailed explanation regarding each configuration property and type check, visit:
5+
* https://jestjs.io/docs/configuration
6+
*/
7+
8+
const config: Config = {
9+
// All imported modules in your tests should be mocked automatically
10+
// automock: false,
11+
12+
// Stop running tests after `n` failures
13+
// bail: 0,
14+
15+
// The directory where Jest should store its cached dependency information
16+
// cacheDirectory: "/private/var/folders/6m/1394pht172qgd7dmw1fwjk100000gn/T/jest_dx",
17+
18+
// Automatically clear mock calls, instances, contexts and results before every test
19+
// clearMocks: true,
20+
21+
// Indicates whether the coverage information should be collected while executing the test
22+
// collectCoverage: false,
23+
24+
// An array of glob patterns indicating a set of files for which coverage information should be collected
25+
// collectCoverageFrom: undefined,
26+
27+
// The directory where Jest should output its coverage files
28+
// coverageDirectory: undefined,
29+
30+
// An array of regexp pattern strings used to skip coverage collection
31+
// coveragePathIgnorePatterns: [
32+
// "/node_modules/"
33+
// ],
34+
35+
// Indicates which provider should be used to instrument code for coverage
36+
coverageProvider: "v8",
37+
38+
// A list of reporter names that Jest uses when writing coverage reports
39+
// coverageReporters: [
40+
// "json",
41+
// "text",
42+
// "lcov",
43+
// "clover"
44+
// ],
45+
46+
// An object that configures minimum threshold enforcement for coverage results
47+
// coverageThreshold: undefined,
48+
49+
// A path to a custom dependency extractor
50+
// dependencyExtractor: undefined,
51+
52+
// Make calling deprecated APIs throw helpful error messages
53+
// errorOnDeprecated: false,
54+
55+
// The default configuration for fake timers
56+
// fakeTimers: {
57+
// "enableGlobally": false
58+
// },
59+
60+
// Force coverage collection from ignored files using an array of glob patterns
61+
// forceCoverageMatch: [],
62+
63+
// A path to a module which exports an async function that is triggered once before all test suites
64+
// globalSetup: undefined,
65+
66+
// A path to a module which exports an async function that is triggered once after all test suites
67+
// globalTeardown: undefined,
68+
69+
// A set of global variables that need to be available in all test environments
70+
// globals: {},
71+
72+
// Insert Jest's globals (expect, test, describe, beforeEach etc.) into the global environment. If you set this to false, you should import from @jest/globals.
73+
// injectGlobals: false,
74+
75+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
76+
// maxWorkers: 1,
77+
78+
// An array of directory names to be searched recursively up from the requiring module's location
79+
// moduleDirectories: [
80+
// "node_modules"
81+
// ],
82+
83+
// An array of file extensions your modules use
84+
moduleFileExtensions: ["js", "mjs", "cjs", "jsx", "ts", "tsx", "json"],
85+
86+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87+
modulePathIgnorePatterns: [".vscode-test/"],
88+
89+
// Activates notifications for test results
90+
// notify: false,
91+
92+
// An enum that specifies notification mode. Requires { notify: true }
93+
// notifyMode: "failure-change",
94+
95+
// A preset that is used as a base for Jest's configuration
96+
// preset: 'ts-jest',
97+
98+
// Run tests from one or more projects
99+
// projects: undefined,
100+
101+
// Use this configuration option to add custom reporters to Jest
102+
// reporters: undefined,
103+
104+
// Automatically reset mock state before every test
105+
resetMocks: true,
106+
107+
// Reset the module registry before running each individual test
108+
// resetModules: false,
109+
110+
// A path to a custom resolver
111+
// resolver: undefined,
112+
113+
// Automatically restore mock state and implementation before every test
114+
// restoreMocks: false,
115+
116+
// The root directory that Jest should scan for tests and modules within
117+
// rootDir: undefined,
118+
119+
// A list of paths to directories that Jest should use to search for files in
120+
// roots: [
121+
// "<rootDir>"
122+
// ],
123+
124+
// Allows you to use a custom runner instead of Jest's default test runner
125+
runner: "vscode",
126+
127+
// The paths to modules that run some code to configure or set up the testing environment before each test
128+
// setupFiles: [],
129+
130+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
131+
setupFilesAfterEnv: ["<rootDir>/../jest.setup.js"],
132+
133+
// The number of seconds after which a test is considered as slow and reported as such in the results.
134+
// slowTestThreshold: 5,
135+
136+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
137+
// snapshotSerializers: [],
138+
139+
// The test environment that will be used for testing
140+
// testEnvironment: 'jsdom',
141+
142+
// Options that will be passed to the testEnvironment
143+
// testEnvironmentOptions: {},
144+
145+
// Adds a location field to test results
146+
// testLocationInResults: false,
147+
148+
// The glob patterns Jest uses to detect test files
149+
testMatch: ["**/*.test.[jt]s"],
150+
151+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
152+
// testPathIgnorePatterns: [
153+
// "/node_modules/"
154+
// ],
155+
156+
// The regexp pattern or array of patterns that Jest uses to detect test files
157+
// testRegex: [],
158+
159+
// This option allows the use of a custom results processor
160+
// testResultsProcessor: undefined,
161+
162+
// This option allows use of a custom test runner
163+
// testRunner: "jest-circus/runner",
164+
165+
// A map from regular expressions to paths to transformers
166+
// transform: {
167+
// '^.+\\.tsx?$': [
168+
// 'ts-jest',
169+
// {
170+
// tsconfig: 'src/view/tsconfig.spec.json',
171+
// },
172+
// ],
173+
// 'node_modules': [
174+
// 'babel-jest',
175+
// {
176+
// presets: [
177+
// '@babel/preset-env'
178+
// ],
179+
// plugins: [
180+
// '@babel/plugin-transform-modules-commonjs',
181+
// ]
182+
// }
183+
// ]
184+
// },
185+
186+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
187+
// 'transformIgnorePatterns': [
188+
// // These use ES modules, so need to be transformed
189+
// 'node_modules/(?!(?:@vscode/webview-ui-toolkit|@microsoft/.+|exenv-es6)/.*)'
190+
// ],
191+
192+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
193+
// unmockedModulePathPatterns: undefined,
194+
195+
// Indicates whether each individual test should be reported during the run
196+
// verbose: undefined,
197+
198+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
199+
// watchPathIgnorePatterns: [],
200+
201+
// Whether to use watchman for file crawling
202+
// watchman: true,
203+
};
204+
205+
export default config;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { env } from "vscode";
2+
3+
(env as any).openExternal = () => {
4+
/**/
5+
};

extensions/ql-vscode/src/vscode-tests/no-workspace/activation.test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file needs to be located in a separate directory from all other tests. The jest-runner-vscode will
2+
// create a new VSCode instance for every directory containing tests, so this will ensure that this
3+
// test is run at the start-up of a new VSCode instance. No other files should be located in this directory since
4+
// those may activate the extension before this test is run.
5+
6+
import * as vscode from "vscode";
7+
8+
// Note that this may open the most recent VSCode workspace.
9+
describe("launching with no specified workspace", () => {
10+
const ext = vscode.extensions.getExtension("GitHub.vscode-codeql");
11+
it("should install the extension", () => {
12+
expect(ext).not.toBeUndefined();
13+
});
14+
it("should not activate the extension at first", () => {
15+
expect(ext!.isActive).toBeFalsy();
16+
});
17+
});

0 commit comments

Comments
 (0)