Skip to content

Commit 86e2bb1

Browse files
Improved test cleanup and config management (#1274)
* clean up test workspace before running tests * improved function that runs code with modified config to properly restore former value
1 parent fc2fb6a commit 86e2bb1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/foam-vscode/src/test/run-tests.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import rf from 'rimraf';
12
import path from 'path';
23
import { runTests } from 'vscode-test';
34
import { runUnit } from './suite-unit';
@@ -34,12 +35,21 @@ async function main() {
3435
// Passed to --extensionTestsPath
3536
const extensionTestsPath = path.join(__dirname, 'suite');
3637

38+
const testWorkspace = path.join(
39+
extensionDevelopmentPath,
40+
'.test-workspace'
41+
);
42+
// clean test workspace
43+
rf.sync(path.join(testWorkspace, '*'));
44+
rf.sync(path.join(testWorkspace, '.vscode'));
45+
rf.sync(path.join(testWorkspace, '.foam'));
46+
3747
// Download VS Code, unzip it and run the integration test
3848
await runTests({
3949
extensionDevelopmentPath,
4050
extensionTestsPath,
4151
launchArgs: [
42-
path.join(extensionDevelopmentPath, '.test-workspace'),
52+
testWorkspace,
4353
'--disable-extensions',
4454
'--disable-workspace-trust',
4555
],

packages/foam-vscode/src/test/test-utils-vscode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ export const runCommand = async <T>(command: string, args: T = undefined) =>
108108
* @param fn the function to execute
109109
*/
110110
export const withModifiedConfiguration = async (key, value, fn: () => void) => {
111-
const old = vscode.workspace.getConfiguration().get(key);
111+
const old = vscode.workspace.getConfiguration().inspect(key);
112112
await vscode.workspace.getConfiguration().update(key, value);
113113
await fn();
114-
await vscode.workspace.getConfiguration().update(key, old);
114+
await vscode.workspace.getConfiguration().update(key, old.workspaceValue);
115115
};
116116

117117
/**

0 commit comments

Comments
 (0)