diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f0816b0a..2c1c687f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 18 - name: Install deps run: npm install - name: Install vsce diff --git a/scripts/test/integration-test.cjs b/scripts/test/integration-test.cjs index d26a6aa0..d7581494 100644 --- a/scripts/test/integration-test.cjs +++ b/scripts/test/integration-test.cjs @@ -2,6 +2,8 @@ const path = require('node:path') const Mocha = require('mocha') const glob = require('glob') +const TESTS_ROOT = path.join(__dirname, '../../tests') + async function run() { await import('tsx') // Create the mocha test @@ -13,7 +15,7 @@ async function run() { }) /** - Before any other tests, run the testSetup.ts file + Before any other tests, run the testSetup.ts file This will set up the test environment necessary for the other tests to run */ mocha.addFile(path.join(__dirname, 'testSetup.ts')) @@ -25,14 +27,13 @@ async function run() { * So you could play with sort order on the tests to investigate */ try { - const testsRoot = path.join(__dirname, '../../src/test') - let files = await glob('**.test.ts', { cwd: testsRoot }) + let files = await glob('**.test.ts', { cwd: TESTS_ROOT }) // Add files to the test suite files.sort((a, b) => { return a.localeCompare(b) }) files.forEach(f => { - mocha.addFile(path.resolve(testsRoot, f)) + mocha.addFile(path.resolve(TESTS_ROOT, f)) }) return new Promise((resolve, reject) => { diff --git a/scripts/test/testSetup.ts b/scripts/test/testSetup.ts index 6d78065b..f3fb915a 100644 --- a/scripts/test/testSetup.ts +++ b/scripts/test/testSetup.ts @@ -1,4 +1,4 @@ -import { activate } from '../../src/test/utils' +import { activate } from '../../tests/utils' /** * This initialization runs once, before the rest of the tests. * It is used to open the test fixture folder and activate the extension. diff --git a/src/test/codefix.test.ts b/tests/codefix.test.ts similarity index 100% rename from src/test/codefix.test.ts rename to tests/codefix.test.ts diff --git a/src/test/diagnostics.test.ts b/tests/diagnostics.test.ts similarity index 100% rename from src/test/diagnostics.test.ts rename to tests/diagnostics.test.ts diff --git a/src/test/fileModifications.test.ts b/tests/fileModifications.test.ts similarity index 100% rename from src/test/fileModifications.test.ts rename to tests/fileModifications.test.ts diff --git a/src/test/utils.ts b/tests/utils.ts similarity index 96% rename from src/test/utils.ts rename to tests/utils.ts index 29a5e0cb..843a92e7 100644 --- a/src/test/utils.ts +++ b/tests/utils.ts @@ -5,6 +5,8 @@ import * as assert from 'assert' export let doc: vscode.TextDocument export let editor: vscode.TextEditor +const FIXTURE_PATH = path.resolve(__dirname, '../fixture') + /** * Prepare the vscode environment for testing by opening the fixture folder * and activating the extension. @@ -15,9 +17,7 @@ export let editor: vscode.TextEditor export async function activate() { // The extensionId is `publisher.name` from package.json const ext = vscode.extensions.getExtension('ast-grep.ast-grep-vscode')! - const fixtureFolderUri = vscode.Uri.file( - path.resolve(__dirname, '../../fixture') - ) + const fixtureFolderUri = vscode.Uri.file(FIXTURE_PATH) await ext.activate() try { // open ast-grep project to locate sgconfig.yml @@ -118,7 +118,7 @@ async function sleep(ms: number) { } export const getDocPath = (p: string) => { - return path.resolve(__dirname, '../../fixture', p) + return path.resolve(FIXTURE_PATH, p) } export const getDocUri = (p: string) => { return vscode.Uri.file(getDocPath(p)) diff --git a/tsconfig.json b/tsconfig.json index a5bf525e..05890041 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "target": "es2020", "lib": ["es2020", "DOM"], "outDir": "out", - "rootDir": "src", + "rootDir": ".", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, @@ -12,6 +12,6 @@ "skipLibCheck": true, "jsx": "react-jsx" }, - "include": ["src"], + "include": ["src", "tests"], "exclude": ["node_modules", ".vscode-test"] }