Skip to content

Commit

Permalink
chore: move tests folder to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Feb 7, 2024
1 parent 521ea74 commit 8f5c736
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions scripts/test/integration-test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'))
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/testSetup.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/test/utils.ts → tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"target": "es2020",
"lib": ["es2020", "DOM"],
"outDir": "out",
"rootDir": "src",
"rootDir": ".",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"sourceMap": true,
"skipLibCheck": true,
"jsx": "react-jsx"
},
"include": ["src"],
"include": ["src", "tests"],
"exclude": ["node_modules", ".vscode-test"]
}

0 comments on commit 8f5c736

Please sign in to comment.