Skip to content

test(remix): Migrate to Vitest #15547

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

Merged
merged 3 commits into from
Mar 3, 2025
Merged
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
2 changes: 1 addition & 1 deletion packages/remix/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
parserOptions: {
jsx: true,
},
ignorePatterns: ['playwright.config.ts', 'vitest.config.ts', 'test/integration/**'],
ignorePatterns: ['playwright.config.ts', 'vitest.config.ts', 'vitest.config.unit.ts', 'test/integration/**'],
extends: ['../../.eslintrc.js'],
overrides: [
{
Expand Down
8 changes: 0 additions & 8 deletions packages/remix/jest.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
"test:integration:client": "yarn playwright install-deps && yarn playwright test test/integration/test/client/ --project='chromium'",
"test:integration:client:ci": "yarn test:integration:client",
"test:integration:server": "export NODE_OPTIONS='--stack-trace-limit=25' && vitest run",
"test:unit": "jest",
"test:watch": "jest --watch",
"test:unit": "vitest run --config vitest.config.unit.ts",
"test:watch": "vitest --watch --config vitest.config.unit.ts",
"yalc:publish": "yalc publish --push --sig"
},
"volta": {
Expand Down
12 changes: 4 additions & 8 deletions packages/remix/test/index.client.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import * as SentryReact from '@sentry/react';
import { describe, vi, it, expect, afterEach, type Mock } from 'vitest';

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

jest.mock('@sentry/react', () => {
return {
__esModule: true,
...jest.requireActual('@sentry/react'),
};
});
vi.mock('@sentry/react', { spy: true });

const reactInit = jest.spyOn(SentryReact, 'init');
const reactInit = SentryReact.init as Mock;

describe('Client init()', () => {
afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();

SentryReact.getGlobalScope().clear();
SentryReact.getIsolationScope().clear();
Expand Down
12 changes: 4 additions & 8 deletions packages/remix/test/index.server.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import * as SentryNode from '@sentry/node';
import { describe, vi, it, expect, afterEach, type Mock } from 'vitest';

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

jest.mock('@sentry/node', () => {
return {
__esModule: true,
...jest.requireActual('@sentry/node'),
};
});
vi.mock('@sentry/node', { spy: true });

const nodeInit = jest.spyOn(SentryNode, 'init');
const nodeInit = SentryNode.init as Mock;

describe('Server init()', () => {
afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();

SentryNode.getGlobalScope().clear();
SentryNode.getIsolationScope().clear();
Expand Down
53 changes: 36 additions & 17 deletions packages/remix/test/scripts/upload-sourcemaps.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
const newMock = jest.fn();
const uploadSourceMapsMock = jest.fn();
const finalizeMock = jest.fn();
const proposeVersionMock = jest.fn(() => '0.1.2.3.4');
import { vi, describe, it, expect, beforeEach } from 'vitest';

jest.mock('@sentry/cli', () => {
return jest.fn().mockImplementation(() => {
return {
execute: jest.fn(),
releases: {
new: newMock,
uploadSourceMaps: uploadSourceMapsMock,
finalize: finalizeMock,
proposeVersion: proposeVersionMock,
},
};
});
});
const newMock = vi.fn();
const uploadSourceMapsMock = vi.fn();
const finalizeMock = vi.fn();
const proposeVersionMock = vi.fn(() => '0.1.2.3.4');

// The createRelease script requires the Sentry CLI, which we need to mock so we
// hook require to do this
async function mock(mockedUri: string, stub: any) {
const { Module } = await import('module');
// @ts-expect-error test
Module._load_original = Module._load;
// @ts-expect-error test
Module._load = (uri, parent) => {
if (uri === mockedUri) return stub;
// @ts-expect-error test
return Module._load_original(uri, parent);
};
}

await vi.hoisted(async () =>
mock(
'@sentry/cli',
vi.fn().mockImplementation(() => {
return {
execute: vi.fn(),
releases: {
new: newMock,
uploadSourceMaps: uploadSourceMapsMock,
finalize: finalizeMock,
proposeVersion: proposeVersionMock,
},
};
}),
),
);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createRelease } = require('../../scripts/createRelease');
Expand Down
8 changes: 6 additions & 2 deletions packages/remix/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"extends": "./tsconfig.json",

"include": ["test/**/*", "vitest.config.ts"],
"include": ["test/**/*", "vitest.config.ts", "vitest.config.unit.ts"],

"compilerOptions": {
"lib": ["DOM", "ES2018"],
"types": ["node", "jest"],
"types": ["node"],
// Required for top-level await in tests
"module": "Node16",
"target": "ES2017",

"esModuleInterop": true
}
}
14 changes: 14 additions & 0 deletions packages/remix/vitest.config.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'vitest/config';

import baseConfig from '../../vite/vite.config';

export default defineConfig({
...baseConfig,
test: {
...baseConfig.test,
// disableConsoleIntercept: true,
// silent: false,
include: ['test/**/*.test.ts'],
exclude: ['**/integration/**/*.test.ts'],
},
});
Loading