Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch to vs code tests #262

Merged
merged 21 commits into from
Feb 26, 2024

Conversation

ffMathy
Copy link
Collaborator

@ffMathy ffMathy commented Feb 23, 2024

This switches to VS Code tests. Unfortunately this has to ditch Vitest in favor of Mocha, which is a requirement for this to work.

But the good thing is that this allows for real integration tests of the extension! They also run super fast, and it will make stabilizing the extension a lot easier.

See official guidance here: https://code.visualstudio.com/api/working-with-extensions/testing-extension

You'll also notice this has led to removing all mocks - they are no longer needed! 😍

package.json Outdated Show resolved Hide resolved
samples/basic/test/add.test.ts Outdated Show resolved Hide resolved
test/pure/testName.test.ts Outdated Show resolved Hide resolved
@hi-ogawa
Copy link
Contributor

Thanks for getting this started! I guess this PR is essentially for this?

@ffMathy
Copy link
Collaborator Author

ffMathy commented Feb 25, 2024

Review comments have been solved.

package.json Outdated Show resolved Hide resolved
.vscode-test.mjs Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@ffMathy
Copy link
Collaborator Author

ffMathy commented Feb 26, 2024

@sheremet-va I fixed your review comments as well now.

@sheremet-va sheremet-va merged commit b5ca1a8 into vitest-dev:main Feb 26, 2024
1 check passed
MilanKovacic pushed a commit to MilanKovacic/vscode that referenced this pull request Feb 26, 2024
* fix: disabling continuous mode prevents future tests from being run

* refactor: remove redundant code

* fix!: remove watch commands since continuous is now a possibility

* fix: linting

* fix: missing subscription removal

* tests: switch to vscode tests

* fix: convert existing tests to mocha

* fix: typecheck

* fix: lint

* fix: test setup

* fix: display ref

* fix: linting

* fix: don't use mocha for sample tests

* fix: bad import

* fix: mocha preload

* fix: linting

* fix: mocha preload directly

* fix: repeated pattern

* revert: sample test changes
]
testCases.forEach(function (testCase) {
const {isWindows, useCustomStartProcess, expectedArgs} = testCase
describe(
Copy link
Contributor

@hi-ogawa hi-ogawa Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these tests are not running because of describe instead of it. After replace describe with it, the tests fail with:

  1) TestRunner
       scheduleRun wrap test patterns if needed, (isWindows: false, customStartProcess: false):
     TypeError: Cannot redefine property: isWindows
        at Function.defineProperty (<anonymous>)
        at Context.<anonymous> (test/runner.test.ts:2:1709)
        at process.processImmediate (node:internal/timers:476:21)

  2) TestRunner
       "after each" hook for "scheduleRun wrap test patterns if needed, (isWindows: false, customStartProcess: false)":
     TypeError: Cannot redefine property: isWindows
        at Function.defineProperty (<anonymous>)
        at Context.<anonymous> (test/runner.test.ts:2:989)
        at process.processImmediate (node:internal/timers:476:21)

Maybe, we actually need to mock something after all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Although that failure doesn't seem to happen due to lack of mocking.

Copy link
Contributor

@hi-ogawa hi-ogawa Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize at that time, but I think this test's purpose was not about "running" but only about cli argument sanitization as written on the left side of the diff:

Mock runVitestWithApi, causing it to return its arguments as its output to allow us to assert their values

Probably the original author wanted to unit test code around here:

async scheduleRun(
testFile: string[] | undefined,
testPattern: string | undefined,
log: { info: (msg: string) => void; error: (line: string) => void } = { info: () => {}, error: console.error },
workspaceEnv: Record<string, string> = {},
vitestCommand: { cmd: string; args: string[] } = this.defaultVitestCommand
? this.defaultVitestCommand
: { cmd: 'npx', args: ['vitest'] },
updateSnapshot = false,
onUpdate?: (files: File[]) => void,
customStartProcess?: (config: StartConfig) => void,
cancellation?: CancellationToken,
): Promise<{ testResultFiles: File[]; output: string }> {
const command = vitestCommand.cmd
const args = [
...vitestCommand.args,
...(testFile ? testFile.map(f => sanitizeFilePath(f)) : []),
] as string[]
if (updateSnapshot)
args.push('--update')
if (testPattern) {
let argsValue = testPattern
if (isWindows && !customStartProcess) {
// Wrap the test pattern in quotes to ensure it is treated as a single argument
argsValue = `"${argsValue.replace(/"/g, '\\"')}"`
}
args.push('-t', argsValue)
}
const workspacePath = sanitizeFilePath(this.workspacePath)
const outputs: string[] = []
const env = { ...process.env, ...workspaceEnv }
let testResultFiles = [] as File[]


I guess another way to test this would be to extract it so that it's easy to unit test and I would normally prefer that, but I haven't read through the code to see if it's possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants