Skip to content

Commit f5cccfb

Browse files
authored
test(remix): Migrate to Vitest (#15547)
1 parent b977fe1 commit f5cccfb

8 files changed

+67
-46
lines changed

packages/remix/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
parserOptions: {
77
jsx: true,
88
},
9-
ignorePatterns: ['playwright.config.ts', 'vitest.config.ts', 'test/integration/**'],
9+
ignorePatterns: ['playwright.config.ts', 'vitest.config.ts', 'vitest.config.unit.ts', 'test/integration/**'],
1010
extends: ['../../.eslintrc.js'],
1111
overrides: [
1212
{

packages/remix/jest.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/remix/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@
104104
"test:integration:client": "yarn playwright install-deps && yarn playwright test test/integration/test/client/ --project='chromium'",
105105
"test:integration:client:ci": "yarn test:integration:client",
106106
"test:integration:server": "export NODE_OPTIONS='--stack-trace-limit=25' && vitest run",
107-
"test:unit": "jest",
108-
"test:watch": "jest --watch",
107+
"test:unit": "vitest run --config vitest.config.unit.ts",
108+
"test:watch": "vitest --watch --config vitest.config.unit.ts",
109109
"yalc:publish": "yalc publish --push --sig"
110110
},
111111
"volta": {

packages/remix/test/index.client.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import * as SentryReact from '@sentry/react';
2+
import { describe, vi, it, expect, afterEach, type Mock } from 'vitest';
23

34
import { init } from '../src/index.client';
45

5-
jest.mock('@sentry/react', () => {
6-
return {
7-
__esModule: true,
8-
...jest.requireActual('@sentry/react'),
9-
};
10-
});
6+
vi.mock('@sentry/react', { spy: true });
117

12-
const reactInit = jest.spyOn(SentryReact, 'init');
8+
const reactInit = SentryReact.init as Mock;
139

1410
describe('Client init()', () => {
1511
afterEach(() => {
16-
jest.clearAllMocks();
12+
vi.clearAllMocks();
1713

1814
SentryReact.getGlobalScope().clear();
1915
SentryReact.getIsolationScope().clear();

packages/remix/test/index.server.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import * as SentryNode from '@sentry/node';
2+
import { describe, vi, it, expect, afterEach, type Mock } from 'vitest';
23

34
import { init } from '../src/index.server';
45

5-
jest.mock('@sentry/node', () => {
6-
return {
7-
__esModule: true,
8-
...jest.requireActual('@sentry/node'),
9-
};
10-
});
6+
vi.mock('@sentry/node', { spy: true });
117

12-
const nodeInit = jest.spyOn(SentryNode, 'init');
8+
const nodeInit = SentryNode.init as Mock;
139

1410
describe('Server init()', () => {
1511
afterEach(() => {
16-
jest.clearAllMocks();
12+
vi.clearAllMocks();
1713

1814
SentryNode.getGlobalScope().clear();
1915
SentryNode.getIsolationScope().clear();

packages/remix/test/scripts/upload-sourcemaps.test.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1-
const newMock = jest.fn();
2-
const uploadSourceMapsMock = jest.fn();
3-
const finalizeMock = jest.fn();
4-
const proposeVersionMock = jest.fn(() => '0.1.2.3.4');
1+
import { vi, describe, it, expect, beforeEach } from 'vitest';
52

6-
jest.mock('@sentry/cli', () => {
7-
return jest.fn().mockImplementation(() => {
8-
return {
9-
execute: jest.fn(),
10-
releases: {
11-
new: newMock,
12-
uploadSourceMaps: uploadSourceMapsMock,
13-
finalize: finalizeMock,
14-
proposeVersion: proposeVersionMock,
15-
},
16-
};
17-
});
18-
});
3+
const newMock = vi.fn();
4+
const uploadSourceMapsMock = vi.fn();
5+
const finalizeMock = vi.fn();
6+
const proposeVersionMock = vi.fn(() => '0.1.2.3.4');
7+
8+
// The createRelease script requires the Sentry CLI, which we need to mock so we
9+
// hook require to do this
10+
async function mock(mockedUri: string, stub: any) {
11+
const { Module } = await import('module');
12+
// @ts-expect-error test
13+
Module._load_original = Module._load;
14+
// @ts-expect-error test
15+
Module._load = (uri, parent) => {
16+
if (uri === mockedUri) return stub;
17+
// @ts-expect-error test
18+
return Module._load_original(uri, parent);
19+
};
20+
}
21+
22+
await vi.hoisted(async () =>
23+
mock(
24+
'@sentry/cli',
25+
vi.fn().mockImplementation(() => {
26+
return {
27+
execute: vi.fn(),
28+
releases: {
29+
new: newMock,
30+
uploadSourceMaps: uploadSourceMapsMock,
31+
finalize: finalizeMock,
32+
proposeVersion: proposeVersionMock,
33+
},
34+
};
35+
}),
36+
),
37+
);
1938

2039
// eslint-disable-next-line @typescript-eslint/no-var-requires
2140
const { createRelease } = require('../../scripts/createRelease');

packages/remix/tsconfig.test.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"extends": "./tsconfig.json",
33

4-
"include": ["test/**/*", "vitest.config.ts"],
4+
"include": ["test/**/*", "vitest.config.ts", "vitest.config.unit.ts"],
55

66
"compilerOptions": {
77
"lib": ["DOM", "ES2018"],
8-
"types": ["node", "jest"],
8+
"types": ["node"],
9+
// Required for top-level await in tests
10+
"module": "Node16",
11+
"target": "ES2017",
12+
913
"esModuleInterop": true
1014
}
1115
}

packages/remix/vitest.config.unit.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
import baseConfig from '../../vite/vite.config';
4+
5+
export default defineConfig({
6+
...baseConfig,
7+
test: {
8+
...baseConfig.test,
9+
// disableConsoleIntercept: true,
10+
// silent: false,
11+
include: ['test/**/*.test.ts'],
12+
exclude: ['**/integration/**/*.test.ts'],
13+
},
14+
});

0 commit comments

Comments
 (0)