Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions integration-tests/ci-visibility/jestEnvironmentAsyncAddTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const NodeEnvironment =
require('jest-environment-node').TestEnvironment ||
require('jest-environment-node')

class CustomEnvironment extends NodeEnvironment {
handleTestEvent (event) {
if (event.name === 'add_test') {
return new Promise(() => {})
}
}
}

module.exports = CustomEnvironment
15 changes: 15 additions & 0 deletions integration-tests/ci-visibility/jestEnvironmentNoSuper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const NodeEnvironment =
require('jest-environment-node').TestEnvironment ||
require('jest-environment-node')

class CustomEnvironment extends NodeEnvironment {
async handleTestEvent (event, state) {
if (!this.global.JEST_STATE_SYMBOL) {
this.global.JEST_STATE_SYMBOL = state
}
}
}

module.exports = CustomEnvironment
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const NodeEnvironment =
require('jest-environment-node').TestEnvironment ||
require('jest-environment-node')

class CustomEnvironment extends NodeEnvironment {
async setup () {
await super.setup()

this.handleTestEvent = async (event, state) => {
if (!this.global.JEST_STATE_SYMBOL) {
this.global.JEST_STATE_SYMBOL = state
}
}
}
}

module.exports = CustomEnvironment
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const NodeEnvironment =
require('jest-environment-node').TestEnvironment ||
require('jest-environment-node')

class CustomEnvironment extends NodeEnvironment {
handleTestEvent = async (event, state) => {
if (!this.global.JEST_STATE_SYMBOL) {
this.global.JEST_STATE_SYMBOL = state
}
}
}

module.exports = CustomEnvironment
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const NodeEnvironment =
require('jest-environment-node').TestEnvironment ||
require('jest-environment-node')

class CustomEnvironment extends NodeEnvironment {
handleTestEvent = async (event, state) => {
if (!this.global.JEST_STATE_SYMBOL) {
this.global.JEST_STATE_SYMBOL = state
}
}

async setup () {}
}

module.exports = CustomEnvironment
4 changes: 4 additions & 0 deletions integration-tests/ci-visibility/run-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ if (process.env.ENABLE_HAPPY_DOM) {
options.testEnvironment = '@happy-dom/jest-environment'
}

if (process.env.CUSTOM_TEST_ENVIRONMENT) {
options.testEnvironment = process.env.CUSTOM_TEST_ENVIRONMENT
}

if (process.env.COLLECT_COVERAGE_FROM) {
options.collectCoverageFrom = process.env.COLLECT_COVERAGE_FROM.split(',')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, test, expect } from 'vitest'

let eventuallyPassAttempts = 0

function wait (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

describe('concurrent early flake detection', () => {
test.concurrent('can retry concurrent tests that eventually pass', async () => {
await wait(20)
expect(1 + 2).to.equal(eventuallyPassAttempts++ === 0 ? 4 : 3)
})

test.concurrent('can retry concurrent tests that always pass', async () => {
await wait(10)
expect(1 + 2).to.equal(3)
})

test('can retry non-concurrent tests in a mixed suite', async () => {
await wait(5)
expect(1 + 2).to.equal(3)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, test, expect } from 'vitest'

let eventuallyPassAttempts = 0
let nonConcurrentEventuallyPassAttempts = 0

function wait (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

describe('concurrent flaky test retries', () => {
test.concurrent('can retry concurrent tests that eventually pass', async () => {
await wait(20)
expect(++eventuallyPassAttempts).to.equal(2)
})

test.concurrent('can retry concurrent tests that never pass', async () => {
await wait(10)
expect(1 + 2).to.equal(4)
})

test.concurrent('does not retry concurrent tests if unnecessary', async () => {
await wait(5)
expect(1 + 2).to.equal(3)
})

test('can retry non-concurrent tests in a mixed suite', async () => {
await wait(1)
expect(++nonConcurrentEventuallyPassAttempts).to.equal(2)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, test, expect } from 'vitest'
import { sum } from './bad-sum'

let attempt = 0

function wait (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

describe('dynamic instrumentation with concurrent tests', () => {
test('serial retry does not use Failed Test Replay', () => {
if (attempt++ === 0) {
expect(sum(11, 2)).to.equal(13)
} else {
expect(sum(1, 2)).to.equal(3)
}
})

test.concurrent('concurrent test disables Failed Test Replay for the file', async () => {
await wait(1)
expect(sum(1, 2)).to.equal(3)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, test, expect } from 'vitest'

describe('concurrent impacted test', () => {
test.concurrent('can mark first concurrent impacted test', () => {
expect(1 + 2).to.equal(3)
})

test.concurrent('can mark second concurrent impacted test', () => {
expect(2 + 2).to.equal(4)
})

test('can mark a non-concurrent impacted test in the same suite', () => {
expect(3 + 2).to.equal(5)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function httpRequest (path) {
})
}

function wait (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

describe('vitest-test-integration-http', () => {
test('can do integration http', async () => {
const testSpan = tracer.scope().active()
Expand All @@ -41,6 +45,84 @@ describe('vitest-test-hook-http', () => {
})
})

describe('vitest-test-concurrent-hook-http', () => {
beforeEach(async () => {
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

afterEach(async () => {
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

test.concurrent('first concurrent hook http is linked to first test span', async () => {
await wait(30)
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

test.concurrent('second concurrent hook http is linked to second test span', async () => {
await wait(10)
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})
})

describe.concurrent('vitest-describe-concurrent-hook-http', () => {
beforeEach(async () => {
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

afterEach(async () => {
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

test('first inherited concurrent hook http is linked to first test span', async () => {
await wait(30)
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

test('second inherited concurrent hook http is linked to second test span', async () => {
await wait(10)
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})
})

describe('vitest-mixed-concurrent-hook-http', () => {
beforeEach(async () => {
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

afterEach(async () => {
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

test('serial hook http is linked to serial test span', async () => {
await wait(5)
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

test.concurrent('first mixed concurrent hook http is linked to first test span', async () => {
await wait(30)
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})

test.concurrent('second mixed concurrent hook http is linked to second test span', async () => {
await wait(10)
const statusCode = await httpRequest('/info')
expect(statusCode).toBe(200)
})
})

describe('vitest-test-before-each-cleanup-http', () => {
beforeEach(async () => {
const statusCode = await httpRequest('/info')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, test, expect } from 'vitest'

function wait (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}

describe('concurrent test management', () => {
test.concurrent('can attempt to fix a concurrent test', async () => {
await wait(20)
// eslint-disable-next-line no-console
console.log('I am running concurrent attempt to fix')
expect(1 + 2).to.equal(4)
})

test.concurrent('can disable a concurrent test', async () => {
await wait(15)
// eslint-disable-next-line no-console
console.log('I am running concurrent disabled')
expect(1 + 2).to.equal(4)
})

test.concurrent('can quarantine a concurrent test', async () => {
await wait(10)
// eslint-disable-next-line no-console
console.log('I am running concurrent quarantined')
expect(1 + 2).to.equal(4)
})

test.concurrent('can pass normally in a concurrent management suite', async () => {
await wait(5)
expect(1 + 2).to.equal(3)
})

test('can attempt to fix a non-concurrent test in a mixed management suite', async () => {
await wait(4)
// eslint-disable-next-line no-console
console.log('I am running non-concurrent attempt to fix')
expect(1 + 2).to.equal(4)
})

test('can disable a non-concurrent test in a mixed management suite', async () => {
await wait(3)
// eslint-disable-next-line no-console
console.log('I am running non-concurrent disabled')
expect(1 + 2).to.equal(4)
})

test('can pass normally beside concurrent management tests', async () => {
await wait(2)
expect(1 + 2).to.equal(3)
})
})
2 changes: 1 addition & 1 deletion integration-tests/cypress/cypress-atr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function shouldTestsRun (type) {
return version === '12.0.0' || version === '14.5.4' || version === 'latest'
}
}
if (DD_MAJOR === 6) {
if (DD_MAJOR >= 6) {
if (NODE_MAJOR <= 16) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cypress/cypress-efd.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function shouldTestsRun (type) {
return version === '12.0.0' || version === '14.5.4' || version === 'latest'
}
}
if (DD_MAJOR === 6) {
if (DD_MAJOR >= 6) {
if (NODE_MAJOR <= 16) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function shouldTestsRun (type) {
return version === '12.0.0' || version === '14.5.4' || version === 'latest'
}
}
if (DD_MAJOR === 6) {
if (DD_MAJOR >= 6) {
if (NODE_MAJOR <= 16) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cypress/cypress-itr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function shouldTestsRun (type) {
return version === '12.0.0' || version === '14.5.4' || version === 'latest'
}
}
if (DD_MAJOR === 6) {
if (DD_MAJOR >= 6) {
if (NODE_MAJOR <= 16) {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function shouldTestsRun (type) {
return version === '12.0.0' || version === '14.5.4' || version === 'latest'
}
}
if (DD_MAJOR === 6) {
if (DD_MAJOR >= 6) {
if (NODE_MAJOR <= 16) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cypress/cypress-reporting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function shouldTestsRun (type) {
return version === '12.0.0' || version === '14.5.4' || version === 'latest'
}
}
if (DD_MAJOR === 6) {
if (DD_MAJOR >= 6) {
if (NODE_MAJOR <= 16) {
return false
}
Expand Down
Loading
Loading