-
Notifications
You must be signed in to change notification settings - Fork 309
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
[test-visibility] Add support for vitest #4415
Merged
Merged
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
0268820
add vitest support wip
juan-fernandez 4b03ee1
better vitest support
juan-fernandez 689d9aa
wip
juan-fernandez 6512002
clean up
juan-fernandez d953763
clean up
juan-fernandez 0d4f4ac
add e2e tests
juan-fernandez 17de859
support 1.6.0 too
juan-fernandez b1ce709
clean up and add error handling
juan-fernandez 81d8a1c
add session error message
juan-fernandez 8c49dbd
add ci job
juan-fernandez b2a163e
remove volta
juan-fernandez 6213755
Merge branch 'master' into juan-fernandez/add-vitest-support
juan-fernandez 420e0dd
support for before after all hooks
juan-fernandez e5ae80f
support beforeeach and aftereach
juan-fernandez 5fd20c7
add test source file
juan-fernandez 7edbaf6
better tests
juan-fernandez 482db61
ts definitions
juan-fernandez cb580df
Merge branch 'master' into juan-fernandez/add-vitest-support
juan-fernandez ba5088c
add support for skipped tests
juan-fernandez 5c570a9
update comment
juan-fernandez 1ddeee8
do not use iitm version and add wildcard logic
juan-fernandez 95c5286
Merge branch 'master' into juan-fernandez/add-vitest-support
juan-fernandez aa20aae
static list of esm plugins
juan-fernandez 5551e63
add safeguard hook
juan-fernandez c15e63c
better regex logic
juan-fernandez ee2b032
remove unused var
juan-fernandez 0d60e30
Merge branch 'master' into juan-fernandez/add-vitest-support
juan-fernandez 37f33e7
move esm first logic to hooks
juan-fernandez b29cfdb
remove dependency on getport
juan-fernandez 6bee656
adding checks for hasSubscriber and asyncresource
juan-fernandez 44ed749
Merge branch 'master' into juan-fernandez/add-vitest-support
juan-fernandez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function sum (a, b) { | ||
return a + b | ||
} |
26 changes: 26 additions & 0 deletions
26
integration-tests/ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, test, expect, beforeEach, afterEach } from 'vitest' | ||
import { sum } from './sum' | ||
|
||
describe('context', () => { | ||
beforeEach(() => { | ||
throw new Error('failed before each') | ||
}) | ||
test('can report failed test', () => { | ||
expect(sum(1, 2)).to.equal(4) | ||
}) | ||
test('can report more', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
}) | ||
|
||
describe('other context', () => { | ||
afterEach(() => { | ||
throw new Error('failed after each') | ||
}) | ||
test('can report passed test', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
test('can report more', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
integration-tests/ci-visibility/vitest-tests/test-visibility-failed-suite.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, test, expect, beforeEach, afterEach } from 'vitest' | ||
import { sum } from './sum' | ||
|
||
let preparedValue = 1 | ||
|
||
describe('test-visibility-failed-suite-first-describe', () => { | ||
beforeEach(() => { | ||
preparedValue = 2 | ||
}) | ||
test('can report failed test', () => { | ||
expect(sum(1, 2)).to.equal(4) | ||
}) | ||
test('can report more', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
expect(preparedValue).to.equal(2) | ||
}) | ||
}) | ||
|
||
describe('test-visibility-failed-suite-second-describe', () => { | ||
afterEach(() => { | ||
preparedValue = 1 | ||
}) | ||
test('can report passed test', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
test('can report more', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
}) |
32 changes: 32 additions & 0 deletions
32
integration-tests/ci-visibility/vitest-tests/test-visibility-passed-suite.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, test, expect } from 'vitest' | ||
import { sum } from './sum' | ||
|
||
describe('context', () => { | ||
test('can report passed test', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
test('can report more', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
}) | ||
|
||
describe('other context', () => { | ||
test('can report passed test', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
test('can report more', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
test.skip('can skip', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
test.todo('can todo', () => { | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
// eslint-disable-next-line | ||
test('can programmatic skip', (context) => { | ||
// eslint-disable-next-line | ||
context.skip() | ||
expect(sum(1, 2)).to.equal(3) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: [ | ||
'ci-visibility/vitest-tests/test-visibility*' | ||
] | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
'use strict' | ||
|
||
const { exec } = require('child_process') | ||
|
||
const { assert } = require('chai') | ||
|
||
const { | ||
createSandbox, | ||
getCiVisAgentlessConfig | ||
} = require('../helpers') | ||
const { FakeCiVisIntake } = require('../ci-visibility-intake') | ||
const { | ||
TEST_STATUS, | ||
TEST_TYPE | ||
} = require('../../packages/dd-trace/src/plugins/util/test') | ||
|
||
// tested with 1.6.0 | ||
const versions = ['latest'] | ||
|
||
versions.forEach((version) => { | ||
describe(`vitest@${version}`, () => { | ||
let sandbox, cwd, receiver, childProcess | ||
|
||
before(async function () { | ||
sandbox = await createSandbox([`vitest@${version}`], true) | ||
cwd = sandbox.folder | ||
}) | ||
|
||
after(async () => { | ||
await sandbox.remove() | ||
}) | ||
|
||
beforeEach(async function () { | ||
receiver = await new FakeCiVisIntake().start() | ||
}) | ||
|
||
afterEach(async () => { | ||
childProcess.kill() | ||
await receiver.stop() | ||
}) | ||
|
||
it('can run and report tests', (done) => { | ||
receiver.gatherPayloadsMaxTimeout(({ url }) => url === '/api/v2/citestcycle', payloads => { | ||
const events = payloads.flatMap(({ payload }) => payload.events) | ||
|
||
const testSessionEvent = events.find(event => event.type === 'test_session_end') | ||
const testModuleEvent = events.find(event => event.type === 'test_module_end') | ||
const testSuiteEvents = events.filter(event => event.type === 'test_suite_end') | ||
const testEvents = events.filter(event => event.type === 'test') | ||
|
||
assert.include(testSessionEvent.content.resource, 'test_session.vitest run') | ||
assert.equal(testSessionEvent.content.meta[TEST_STATUS], 'fail') | ||
assert.include(testModuleEvent.content.resource, 'test_module.vitest run') | ||
assert.equal(testModuleEvent.content.meta[TEST_STATUS], 'fail') | ||
assert.equal(testSessionEvent.content.meta[TEST_TYPE], 'test') | ||
assert.equal(testModuleEvent.content.meta[TEST_TYPE], 'test') | ||
|
||
const passedSuite = testSuiteEvents.find( | ||
suite => suite.content.resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-passed-suite.mjs' | ||
) | ||
assert.equal(passedSuite.content.meta[TEST_STATUS], 'pass') | ||
|
||
const failedSuite = testSuiteEvents.find( | ||
suite => suite.content.resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' | ||
) | ||
assert.equal(failedSuite.content.meta[TEST_STATUS], 'fail') | ||
|
||
const failedSuiteHooks = testSuiteEvents.find( | ||
suite => suite.content.resource === 'test_suite.ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs' | ||
) | ||
assert.equal(failedSuiteHooks.content.meta[TEST_STATUS], 'fail') | ||
|
||
assert.includeMembers(testEvents.map(test => test.content.resource), | ||
[ | ||
'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' + | ||
'.test-visibility-failed-suite-first-describe can report failed test', | ||
'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' + | ||
'.test-visibility-failed-suite-first-describe can report more', | ||
'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' + | ||
'.test-visibility-failed-suite-second-describe can report passed test', | ||
'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' + | ||
'.test-visibility-failed-suite-second-describe can report more', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.context can report passed test', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.context can report more', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can report passed test', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can report more', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can skip', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can todo', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report failed test', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report more', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report passed test', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report more' | ||
] | ||
) | ||
|
||
const failedTests = testEvents.filter(test => test.content.meta[TEST_STATUS] === 'fail') | ||
|
||
assert.includeMembers( | ||
failedTests.map(test => test.content.resource), | ||
[ | ||
'ci-visibility/vitest-tests/test-visibility-failed-suite.mjs' + | ||
'.test-visibility-failed-suite-first-describe can report failed test', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report failed test', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.context can report more', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report passed test', | ||
'ci-visibility/vitest-tests/test-visibility-failed-hooks.mjs.other context can report more' | ||
] | ||
) | ||
|
||
const skippedTests = testEvents.filter(test => test.content.meta[TEST_STATUS] === 'skip') | ||
|
||
assert.includeMembers( | ||
skippedTests.map(test => test.content.resource), | ||
[ | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can skip', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can todo', | ||
'ci-visibility/vitest-tests/test-visibility-passed-suite.mjs.other context can programmatic skip' | ||
] | ||
) | ||
// TODO: check error messages | ||
}).then(() => done()).catch(done) | ||
|
||
childProcess = exec( | ||
'./node_modules/.bin/vitest run', | ||
{ | ||
cwd, | ||
env: { | ||
...getCiVisAgentlessConfig(receiver.port), | ||
// maybe only in node@20 | ||
NODE_OPTIONS: '--import dd-trace/register.js -r dd-trace/ci/init' // ESM requires more flags | ||
}, | ||
stdio: 'pipe' | ||
} | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated fix