Use ts-jest for running integration tests

Instead of running the integration tests from the `out` directory, this
will run the integration tests from the `src` directory using `ts-jest`.

Unfortunately, we are not able to use TypeScript files for the
`jest-runner-vscode` configuration since `cosmiconfig` (the package that
handles the configuration loading for `jest-runner-vscode`) doesn't
support loading TypeScript files by default.
This commit is contained in:
Koen Vlaswinkel
2022-11-25 13:06:03 +01:00
parent 754cad3815
commit a23a8f78dd
11 changed files with 56 additions and 54 deletions

View File

@@ -8,8 +8,8 @@ module.exports = {
projects: [ projects: [
"<rootDir>/src/view", "<rootDir>/src/view",
"<rootDir>/test", "<rootDir>/test",
"<rootDir>/out/vscode-tests/cli-integration", "<rootDir>/src/vscode-tests/cli-integration",
"<rootDir>/out/vscode-tests/no-workspace", "<rootDir>/src/vscode-tests/no-workspace",
"<rootDir>/out/vscode-tests/minimal-workspace", "<rootDir>/src/vscode-tests/minimal-workspace",
], ],
}; };

View File

@@ -1273,9 +1273,9 @@
"test:unit": "jest --projects test", "test:unit": "jest --projects test",
"test:view": "jest --projects src/view", "test:view": "jest --projects src/view",
"integration": "npm-run-all integration:*", "integration": "npm-run-all integration:*",
"integration:no-workspace": "jest --projects out/vscode-tests/no-workspace", "integration:no-workspace": "jest --projects src/vscode-tests/no-workspace",
"integration:minimal-workspace": "jest --projects out/vscode-tests/minimal-workspace", "integration:minimal-workspace": "jest --projects src/vscode-tests/minimal-workspace",
"cli-integration": "jest --projects out/vscode-tests/cli-integration", "cli-integration": "jest --projects src/vscode-tests/cli-integration",
"update-vscode": "node ./node_modules/vscode/bin/install", "update-vscode": "node ./node_modules/vscode/bin/install",
"format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix", "format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix",
"lint": "eslint . --ext .ts,.tsx --max-warnings=0", "lint": "eslint . --ext .ts,.tsx --max-warnings=0",

View File

@@ -1,10 +1,12 @@
import * as path from "path"; const path = require("path");
import { RunnerOptions } from "jest-runner-vscode"; const {
config: baseConfig,
rootDir,
} = require("../jest-runner-vscode.config.base");
import baseConfig, { rootDir } from "../jest-runner-vscode.config.base"; /** @type import("jest-runner-vscode").RunnerOptions */
const config = {
const config: RunnerOptions = {
...baseConfig, ...baseConfig,
launchArgs: [ launchArgs: [
...(baseConfig.launchArgs ?? []), ...(baseConfig.launchArgs ?? []),
@@ -25,6 +27,4 @@ const config: RunnerOptions = {
}, },
}; };
// We are purposefully not using export default here since that would result in an ESModule, which doesn't seem to be
// supported properly by jest-runner-vscode (cosmiconfig doesn't really seem to support it).
module.exports = config; module.exports = config;

View File

@@ -4,8 +4,8 @@ import baseConfig from "../jest.config.base";
const config: Config = { const config: Config = {
...baseConfig, ...baseConfig,
runner: "<rootDir>/jest-runner-cli-integration.js", runner: "<rootDir>/jest-runner-cli-integration.ts",
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"], setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
}; };
export default config; export default config;

View File

@@ -94,7 +94,7 @@ const queryTestCases: QueryTestCase[] = [
]; ];
const db: messages.Dataset = { const db: messages.Dataset = {
dbDir: path.join(__dirname, "../test-db"), dbDir: path.join(__dirname, "../../../.vscode-test/test-db"),
workingSet: "default", workingSet: "default",
}; };

View File

@@ -1,12 +1,12 @@
import * as path from "path"; const path = require("path");
import * as tmp from "tmp-promise"; const tmp = require("tmp-promise");
import { RunnerOptions } from "jest-runner-vscode";
export const tmpDir = tmp.dirSync({ unsafeCleanup: true }); const tmpDir = tmp.dirSync({ unsafeCleanup: true });
export const rootDir = path.resolve(__dirname, "../.."); const rootDir = path.resolve(__dirname, "../..");
const config: RunnerOptions = { /** @type import("jest-runner-vscode").RunnerOptions */
const config = {
version: "stable", version: "stable",
launchArgs: [ launchArgs: [
"--disable-gpu", "--disable-gpu",
@@ -20,4 +20,8 @@ if (process.env.VSCODE_INSPECTOR_OPTIONS) {
config.launchArgs?.push("--inspect-extensions", "9223"); config.launchArgs?.push("--inspect-extensions", "9223");
} }
export default config; module.exports = {
config,
tmpDir,
rootDir,
};

View File

@@ -93,7 +93,7 @@ const config: Config = {
// notifyMode: "failure-change", // notifyMode: "failure-change",
// A preset that is used as a base for Jest's configuration // A preset that is used as a base for Jest's configuration
// preset: 'ts-jest', preset: "ts-jest",
// Run tests from one or more projects // Run tests from one or more projects
// projects: undefined, // projects: undefined,
@@ -128,7 +128,7 @@ const config: Config = {
// setupFiles: [], // setupFiles: [],
// A list of paths to modules that run some code to configure or set up the testing framework before each test // A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: ["<rootDir>/../jest.setup.js"], setupFilesAfterEnv: ["<rootDir>/../jest.setup.ts"],
// The number of seconds after which a test is considered as slow and reported as such in the results. // The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5, // slowTestThreshold: 5,

View File

@@ -0,0 +1,18 @@
const path = require("path");
const {
config: baseConfig,
rootDir,
} = require("../jest-runner-vscode.config.base");
/** @type import("jest-runner-vscode").RunnerOptions */
const config = {
...baseConfig,
launchArgs: [
...(baseConfig.launchArgs ?? []),
"--disable-extensions",
path.resolve(rootDir, "test/data"),
],
};
module.exports = config;

View File

@@ -1,17 +0,0 @@
import * as path from "path";
import { RunnerOptions } from "jest-runner-vscode";
import baseConfig, { rootDir } from "../jest-runner-vscode.config.base";
const config: RunnerOptions = {
...baseConfig,
launchArgs: [
...(baseConfig.launchArgs ?? []),
"--disable-extensions",
path.resolve(rootDir, "test/data"),
],
};
// We are purposefully not using export default here since that would result in an ESModule, which doesn't seem to be
// supported properly by jest-runner-vscode (cosmiconfig doesn't really seem to support it).
module.exports = config;

View File

@@ -0,0 +1,9 @@
const { config: baseConfig } = require("../jest-runner-vscode.config.base");
/** @type import("jest-runner-vscode").RunnerOptions */
const config = {
...baseConfig,
launchArgs: [...(baseConfig.launchArgs ?? []), "--disable-extensions"],
};
module.exports = config;

View File

@@ -1,12 +0,0 @@
import { RunnerOptions } from "jest-runner-vscode";
import baseConfig from "../jest-runner-vscode.config.base";
const config: RunnerOptions = {
...baseConfig,
launchArgs: [...(baseConfig.launchArgs ?? []), "--disable-extensions"],
};
// We are purposefully not using export default here since that would result in an ESModule, which doesn't seem to be
// supported properly by jest-runner-vscode (cosmiconfig doesn't really seem to support it).
module.exports = config;