Skip to content

Commit

Permalink
Improved test cleanup and config management (#1274)
Browse files Browse the repository at this point in the history
* clean up test workspace before running tests

* improved function that runs code with modified config to properly restore former value
  • Loading branch information
riccardoferretti authored Aug 21, 2023
1 parent fc2fb6a commit 86e2bb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion packages/foam-vscode/src/test/run-tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import rf from 'rimraf';
import path from 'path';
import { runTests } from 'vscode-test';
import { runUnit } from './suite-unit';
Expand Down Expand Up @@ -34,12 +35,21 @@ async function main() {
// Passed to --extensionTestsPath
const extensionTestsPath = path.join(__dirname, 'suite');

const testWorkspace = path.join(
extensionDevelopmentPath,
'.test-workspace'
);
// clean test workspace
rf.sync(path.join(testWorkspace, '*'));
rf.sync(path.join(testWorkspace, '.vscode'));
rf.sync(path.join(testWorkspace, '.foam'));

// Download VS Code, unzip it and run the integration test
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
path.join(extensionDevelopmentPath, '.test-workspace'),
testWorkspace,
'--disable-extensions',
'--disable-workspace-trust',
],
Expand Down
4 changes: 2 additions & 2 deletions packages/foam-vscode/src/test/test-utils-vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ export const runCommand = async <T>(command: string, args: T = undefined) =>
* @param fn the function to execute
*/
export const withModifiedConfiguration = async (key, value, fn: () => void) => {
const old = vscode.workspace.getConfiguration().get(key);
const old = vscode.workspace.getConfiguration().inspect(key);
await vscode.workspace.getConfiguration().update(key, value);
await fn();
await vscode.workspace.getConfiguration().update(key, old);
await vscode.workspace.getConfiguration().update(key, old.workspaceValue);
};

/**
Expand Down

0 comments on commit 86e2bb1

Please sign in to comment.