-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ugaitz/rasp-blocking
- Loading branch information
Showing
24 changed files
with
906 additions
and
26 deletions.
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
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
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
Oops, something went wrong.