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

test(node-integration): Migrate to Vitest #15499

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
9 changes: 0 additions & 9 deletions dev-packages/node-integration-tests/jest.config.js

This file was deleted.

8 changes: 0 additions & 8 deletions dev-packages/node-integration-tests/jest.setup.js

This file was deleted.

3 changes: 1 addition & 2 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"fix": "eslint . --format stylish --fix",
"type-check": "tsc",
"pretest": "yarn express-v5-install",
"test": "jest --config ./jest.config.js",
"test:no-prisma": "jest --config ./jest.config.js",
"test": "vitest run",
"test:watch": "yarn test --watch"
},
"dependencies": {
Expand Down
85 changes: 49 additions & 36 deletions dev-packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Event } from '@sentry/core';
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';

const ANR_EVENT = {
Expand Down Expand Up @@ -111,18 +112,23 @@ describe('should report ANR when event loop blocked', () => {
cleanupChildProcesses();
});

test('CJS', done => {
createRunner(__dirname, 'basic.js').withMockSentryServer().expect({ event: ANR_EVENT_WITH_DEBUG_META }).start(done);
test('CJS', async () => {
await createRunner(__dirname, 'basic.js')
.withMockSentryServer()
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.start()
.completed();
});

test('ESM', done => {
createRunner(__dirname, 'basic.mjs')
test('ESM', async () => {
await createRunner(__dirname, 'basic.mjs')
.withMockSentryServer()
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.start(done);
.start()
.completed();
});

test('Custom appRootPath', done => {
test('Custom appRootPath', async () => {
const ANR_EVENT_WITH_SPECIFIC_DEBUG_META: Event = {
...ANR_EVENT_WITH_SCOPE,
debug_meta: {
Expand All @@ -136,52 +142,57 @@ describe('should report ANR when event loop blocked', () => {
},
};

createRunner(__dirname, 'app-path.mjs')
await createRunner(__dirname, 'app-path.mjs')
.withMockSentryServer()
.expect({ event: ANR_EVENT_WITH_SPECIFIC_DEBUG_META })
.start(done);
.start()
.completed();
});

test('multiple events via maxAnrEvents', done => {
createRunner(__dirname, 'basic-multiple.mjs')
test('multiple events via maxAnrEvents', async () => {
await createRunner(__dirname, 'basic-multiple.mjs')
.withMockSentryServer()
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.expect({ event: ANR_EVENT_WITH_DEBUG_META })
.start(done);
.start()
.completed();
});

test('blocked indefinitely', done => {
createRunner(__dirname, 'indefinite.mjs').withMockSentryServer().expect({ event: ANR_EVENT }).start(done);
test('blocked indefinitely', async () => {
await createRunner(__dirname, 'indefinite.mjs')
.withMockSentryServer()
.expect({ event: ANR_EVENT })
.start()
.completed();
});

test("With --inspect the debugger isn't used", done => {
createRunner(__dirname, 'basic.mjs')
test("With --inspect the debugger isn't used", async () => {
await createRunner(__dirname, 'basic.mjs')
.withMockSentryServer()
.withFlags('--inspect')
.expect({ event: ANR_EVENT_WITHOUT_STACKTRACE })
.start(done);
.start()
.completed();
});

test('should exit', done => {
test('should exit', async () => {
const runner = createRunner(__dirname, 'should-exit.js').start();

setTimeout(() => {
expect(runner.childHasExited()).toBe(true);
done();
}, 5_000);
await new Promise(resolve => setTimeout(resolve, 5_000));

expect(runner.childHasExited()).toBe(true);
});

test('should exit forced', done => {
test('should exit forced', async () => {
const runner = createRunner(__dirname, 'should-exit-forced.js').start();

setTimeout(() => {
expect(runner.childHasExited()).toBe(true);
done();
}, 5_000);
await new Promise(resolve => setTimeout(resolve, 5_000));

expect(runner.childHasExited()).toBe(true);
});

test('With session', done => {
createRunner(__dirname, 'basic-session.js')
test('With session', async () => {
await createRunner(__dirname, 'basic-session.js')
.withMockSentryServer()
.unignore('session')
.expect({
Expand All @@ -194,15 +205,16 @@ describe('should report ANR when event loop blocked', () => {
},
})
.expect({ event: ANR_EVENT_WITH_SCOPE })
.start(done);
.start()
.completed();
});

test('from forked process', done => {
createRunner(__dirname, 'forker.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
test('from forked process', async () => {
await createRunner(__dirname, 'forker.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start().completed();
});

test('worker can be stopped and restarted', done => {
createRunner(__dirname, 'stop-and-start.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start(done);
test('worker can be stopped and restarted', async () => {
await createRunner(__dirname, 'stop-and-start.js').expect({ event: ANR_EVENT_WITH_SCOPE }).start().completed();
});

const EXPECTED_ISOLATED_EVENT = {
Expand Down Expand Up @@ -231,10 +243,11 @@ describe('should report ANR when event loop blocked', () => {
},
};

test('fetches correct isolated scope', done => {
createRunner(__dirname, 'isolated.mjs')
test('fetches correct isolated scope', async () => {
await createRunner(__dirname, 'isolated.mjs')
.withMockSentryServer()
.expect({ event: EXPECTED_ISOLATED_EVENT })
.start(done);
.start()
.completed();
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

const EXPECTED_TRANSCATION = {
Expand All @@ -7,7 +8,7 @@ const EXPECTED_TRANSCATION = {
description: 'S3.PutObject',
op: 'rpc',
origin: 'auto.otel.aws',
data: {
data: expect.objectContaining({
'sentry.origin': 'auto.otel.aws',
'sentry.op': 'rpc',
'rpc.system': 'aws-api',
Expand All @@ -16,7 +17,7 @@ const EXPECTED_TRANSCATION = {
'aws.region': 'us-east-1',
'aws.s3.bucket': 'ot-demo-test',
'otel.kind': 'CLIENT',
},
}),
}),
]),
};
Expand All @@ -26,7 +27,11 @@ describe('awsIntegration', () => {
cleanupChildProcesses();
});

test('should auto-instrument aws-sdk v2 package.', done => {
createRunner(__dirname, 'scenario.js').ignore('event').expect({ transaction: EXPECTED_TRANSCATION }).start(done);
test('should auto-instrument aws-sdk v2 package.', async () => {
await createRunner(__dirname, 'scenario.js')
.ignore('event')
.expect({ transaction: EXPECTED_TRANSCATION })
.start()
.completed();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Event } from '@sentry/core';
import { afterAll, expect, test } from 'vitest';
import { conditionalTest } from '../../../utils';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

Expand Down Expand Up @@ -39,10 +40,11 @@ conditionalTest({ min: 20 })('should capture process and thread breadcrumbs', ()
cleanupChildProcesses();
});

test('ESM', done => {
createRunner(__dirname, 'app.mjs')
test('ESM', async () => {
await createRunner(__dirname, 'app.mjs')
.withMockSentryServer()
.expect({ event: EVENT as Event })
.start(done);
.start()
.completed();
});
});
17 changes: 9 additions & 8 deletions dev-packages/node-integration-tests/suites/child-process/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Event } from '@sentry/core';
import { afterAll, describe, expect, test } from 'vitest';
import { conditionalTest } from '../../utils';
import { cleanupChildProcesses, createRunner } from '../../utils/runner';

Expand Down Expand Up @@ -44,22 +45,22 @@ describe('should capture child process events', () => {
});

conditionalTest({ min: 20 })('worker', () => {
test('ESM', done => {
createRunner(__dirname, 'worker.mjs').expect({ event: WORKER_EVENT }).start(done);
test('ESM', async () => {
await createRunner(__dirname, 'worker.mjs').expect({ event: WORKER_EVENT }).start().completed();
});

test('CJS', done => {
createRunner(__dirname, 'worker.js').expect({ event: WORKER_EVENT }).start(done);
test('CJS', async () => {
await createRunner(__dirname, 'worker.js').expect({ event: WORKER_EVENT }).start().completed();
});
});

conditionalTest({ min: 20 })('fork', () => {
test('ESM', done => {
createRunner(__dirname, 'fork.mjs').expect({ event: CHILD_EVENT }).start(done);
test('ESM', async () => {
await createRunner(__dirname, 'fork.mjs').expect({ event: CHILD_EVENT }).start().completed();
});

test('CJS', done => {
createRunner(__dirname, 'fork.js').expect({ event: CHILD_EVENT }).start(done);
test('CJS', async () => {
await createRunner(__dirname, 'fork.js').expect({ event: CHILD_EVENT }).start().completed();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { afterAll, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

afterAll(() => {
cleanupChildProcesses();
});

test('should record client report for beforeSend', done => {
createRunner(__dirname, 'scenario.ts')
test('should record client report for beforeSend', async () => {
await createRunner(__dirname, 'scenario.ts')
.unignore('client_report')
.expect({
client_report: {
Expand All @@ -29,5 +30,6 @@ test('should record client report for beforeSend', done => {
],
},
})
.start(done);
.start()
.completed();
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { afterAll, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';

afterAll(() => {
cleanupChildProcesses();
});

test('should record client report for event processors', done => {
createRunner(__dirname, 'scenario.ts')
test('should record client report for event processors', async () => {
await createRunner(__dirname, 'scenario.ts')
.unignore('client_report')
.expect({
client_report: {
Expand All @@ -29,5 +30,6 @@ test('should record client report for event processors', done => {
],
},
})
.start(done);
.start()
.completed();
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { afterAll, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';

afterAll(() => {
cleanupChildProcesses();
});

test('should flush client reports automatically after the timeout interval', done => {
createRunner(__dirname, 'scenario.ts')
test('should flush client reports automatically after the timeout interval', async () => {
await createRunner(__dirname, 'scenario.ts')
.unignore('client_report')
.expect({
client_report: {
Expand All @@ -18,5 +19,6 @@ test('should flush client reports automatically after the timeout interval', don
],
},
})
.start(done);
.start()
.completed();
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { join } from 'path';
import { describe, expect, test } from 'vitest';
import { createRunner } from '../../../utils/runner';

describe('ContextLines integration in ESM', () => {
test('reads encoded context lines from filenames with spaces', done => {
test('reads encoded context lines from filenames with spaces', async () => {
expect.assertions(1);
const instrumentPath = join(__dirname, 'instrument.mjs');

createRunner(__dirname, 'scenario with space.mjs')
await createRunner(__dirname, 'scenario with space.mjs')
.withFlags('--import', instrumentPath)
.expect({
event: {
Expand Down Expand Up @@ -34,15 +35,16 @@ describe('ContextLines integration in ESM', () => {
},
},
})
.start(done);
.start()
.completed();
});
});

describe('ContextLines integration in CJS', () => {
test('reads context lines from filenames with spaces', done => {
test('reads context lines from filenames with spaces', async () => {
expect.assertions(1);

createRunner(__dirname, 'scenario with space.cjs')
await createRunner(__dirname, 'scenario with space.cjs')
.expect({
event: {
exception: {
Expand Down Expand Up @@ -77,6 +79,7 @@ describe('ContextLines integration in CJS', () => {
},
},
})
.start(done);
.start()
.completed();
});
});
Loading
Loading