Skip to content

Commit 2fbb43f

Browse files
committed
Use separate data directories for unit test instances
Exactly as we do for the e2e tests.
1 parent 902a820 commit 2fbb43f

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
],
159159
"moduleNameMapper": {
160160
"^.+\\.(css|less)$": "<rootDir>/test/utils/cssStub.ts"
161-
}
161+
},
162+
"globalSetup": "<rootDir>/test/utils/globalUnitSetup.ts"
162163
}
163164
}

test/playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const config: PlaywrightTestConfig = {
1212
testDir: path.join(__dirname, "e2e"), // Search for tests in this directory.
1313
timeout: 60000, // Each test is given 60 seconds.
1414
retries: process.env.CI ? 2 : 1, // Retry in CI due to flakiness.
15-
globalSetup: require.resolve("./utils/globalSetup.ts"),
15+
globalSetup: require.resolve("./utils/globalE2eSetup.ts"),
1616
reporter: "list",
1717
// Put any shared options on the top level.
1818
use: {

test/utils/globalSetup.ts renamed to test/utils/globalE2eSetup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { clean } from "./helpers"
66
import * as wtfnode from "./wtfnode"
77

88
/**
9-
* Perform workspace cleanup and authenticate. This should be set up to run
10-
* before our tests execute.
9+
* Perform workspace cleanup and authenticate. This should be ran before e2e
10+
* tests execute.
1111
*/
1212
export default async function () {
1313
console.log("\n🚨 Running Global Setup for Playwright End-to-End Tests")

test/utils/globalUnitSetup.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { workspaceDir } from "./constants"
2+
import { clean } from "./helpers"
3+
4+
/**
5+
* Perform workspace cleanup. This should be ran before unit tests execute.
6+
*/
7+
export default async function () {
8+
await clean(workspaceDir)
9+
}

test/utils/integration.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
import { promises as fs } from "fs"
2+
import * as path from "path"
13
import { parse, parseConfigFile, setDefaults } from "../../src/node/cli"
24
import { runCodeServer } from "../../src/node/main"
5+
import { workspaceDir } from "./constants"
6+
import { tmpdir } from "./helpers"
37
import * as httpserver from "./httpserver"
48

59
export async function setup(argv: string[], configFile?: string): Promise<httpserver.HttpServer> {
6-
argv = ["--bind-addr=localhost:0", "--log=warn", ...argv]
10+
// This will be used as the data directory to ensure instances do not bleed
11+
// into each other.
12+
const dir = await tmpdir(workspaceDir)
713

8-
const cliArgs = parse(argv)
14+
// VS Code complains if the logs dir is missing which spams the output.
15+
// TODO: Does that mean we are not creating it when we should be?
16+
await fs.mkdir(path.join(dir, "logs"))
17+
18+
const cliArgs = parse([
19+
`--config=${path.join(dir, "config.yaml")}`,
20+
`--user-data-dir=${dir}`,
21+
"--bind-addr=localhost:0",
22+
"--log=warn",
23+
...argv,
24+
])
925
const configArgs = parseConfigFile(configFile || "", "test/integration.ts")
1026
const args = await setDefaults(cliArgs, configArgs)
1127

0 commit comments

Comments
 (0)