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

chore: migrate to vitest #33

Merged
merged 1 commit into from
Feb 20, 2024
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 .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"rules": {}
},
{
"files": ["jest.setup.ts", "**/__fixtures__/**/*", "**/*.test.mts"],
"files": ["**/__fixtures__/**/*", "**/*.test.mts", "**/vite.config.mts"],
"rules": {
"import/no-extraneous-dependencies": "off"
}
Expand Down
7 changes: 1 addition & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"recommendations": [
"nrwl.angular-console",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"firsttris.vscode-jest-runner"
]
"recommendations": ["nrwl.angular-console", "esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
2 changes: 1 addition & 1 deletion beachball.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
'**/__fixtures__/**',
'**/*.test.mts',
'**/.eslintrc.json',
'**/jest.config.js',
'**/vite.config.mts',
'**/project.json',
'**/README.md',
],
Expand Down
7 changes: 7 additions & 0 deletions change/monosize-35108a61-77ba-418c-a97d-02157caf7db7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: migrate to vitest",
"packageName": "monosize",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: migrate to vitest",
"packageName": "monosize-storage-azure",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: migrate to vitest",
"packageName": "monosize-storage-upstash",
"email": "[email protected]",
"dependentChangeType": "none"
}
5 changes: 0 additions & 5 deletions jest.config.ts

This file was deleted.

15 changes: 0 additions & 15 deletions jest.preset.js

This file was deleted.

15 changes: 0 additions & 15 deletions jest.resolver.js

This file was deleted.

13 changes: 10 additions & 3 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"targetDefaults": {
"build": { "cache": true },
"build": {
"cache": true
},
"lint": {
"cache": true,
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"]
},
"test": { "cache": true },
"e2e": { "cache": true }
"test": {
"cache": true,
"inputs": ["default", "^default"]
},
"e2e": {
"cache": true
}
},
"extends": "@nx/workspace/presets/core.json",
"affected": {
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,35 @@
"devDependencies": {
"@nx/eslint": "17.0.0",
"@nx/eslint-plugin": "17.0.0",
"@nx/jest": "17.0.0",
"@nx/js": "17.0.0",
"@nx/vite": "17.0.0",
"@nx/workspace": "17.0.0",
"@swc-node/register": "~1.6.7",
"@swc/core": "~1.3.85",
"@types/babel__core": "7.20.5",
"@types/glob": "8.0.0",
"@types/jest": "29.4.4",
"@types/node": "16.18.3",
"@types/prettier": "^2.7.3",
"@types/tmp": "0.2.3",
"@types/yargs": "17.0.32",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@vitest/coverage-v8": "~0.32.0",
"@vitest/ui": "~0.32.0",
"beachball": "2.31.5",
"eslint": "8.46.0",
"eslint-config-prettier": "9.0.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-unicorn": "48.0.1",
"jest": "29.4.3",
"nano-staged": "0.8.0",
"nx": "17.0.0",
"simple-git-hooks": "2.9.0",
"syncpack": "11.2.1",
"ts-jest": "29.1.1",
"ts-jest-mock-import-meta": "1.1.0",
"ts-node": "10.9.1",
"typescript": "5.1.6"
"typescript": "5.1.6",
"vite": "~4.3.9",
"vitest": "~0.32.0"
},
"dependencies": {
"@azure/data-tables": "^13.0.0",
Expand Down
17 changes: 0 additions & 17 deletions packages/monosize-storage-azure/jest.config.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/monosize-storage-azure/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
}
},
"test": {
"executor": "@nx/jest:jest",
"executor": "@nx/vite:test",
"outputs": ["{workspaceRoot}/coverage/packages/monosize-storage-azure"],
"options": {
"jestConfig": "packages/monosize-storage-azure/jest.config.ts",
"passWithNoTests": true
}
}
Expand Down
11 changes: 6 additions & 5 deletions packages/monosize-storage-azure/src/getRemoteReport.test.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const fetch = jest.fn();
jest.mock('node-fetch', () => fetch);

import type { Response } from 'node-fetch';
import { beforeEach, describe, expect, it, vitest } from 'vitest';

import { createGetRemoteReport } from './getRemoteReport.mjs';
import type { AzureStorageConfig } from './types.mjs';
import { sampleReport } from './__fixture__/sampleReports.mjs';

const fetch = vitest.hoisted(() => vitest.fn());
vitest.mock('node-fetch', () => ({ default: fetch }));

const testConfig: AzureStorageConfig = {
endpoint: 'https://localhost',
};
Expand All @@ -17,7 +18,7 @@ function noop() {

describe('getRemoteReport', () => {
beforeEach(() => {
jest.resetAllMocks();
vitest.resetAllMocks();
});

it('fetches a remote report', async () => {
Expand Down Expand Up @@ -46,7 +47,7 @@ describe('getRemoteReport', () => {
.mockImplementationOnce(() => Promise.reject(new Error('A fetch error')))
.mockImplementation(() => Promise.resolve(value));

jest.spyOn(console, 'log').mockImplementation(noop);
vitest.spyOn(console, 'log').mockImplementation(noop);

const getRemoteReport = createGetRemoteReport(testConfig);
const { remoteReport } = await getRemoteReport('main');
Expand Down
26 changes: 13 additions & 13 deletions packages/monosize-storage-azure/src/uploadReportToRemote.test.mts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { beforeEach, beforeAll, describe, expect, it, vitest, type Mock } from 'vitest';
import { createRowKey, ENTRIES_PER_CHUNK, splitArrayToChunks, uploadReportToRemote } from './uploadReportToRemote.mjs';

import { sampleReport, bigReport } from './__fixture__/sampleReports.mjs';
import { BundleSizeReportEntry } from 'monosize';

const getRemoteReport = jest.fn() as jest.Mock<
Array<BundleSizeReportEntry & { partitionKey: string; rowKey: string }>,
[]
>;
const submitTransaction = jest.fn();
const getRemoteReport = vitest.hoisted(
() => vitest.fn() as Mock<Array<BundleSizeReportEntry & { partitionKey: string; rowKey: string }>>,
);
const submitTransaction = vitest.hoisted(() => vitest.fn());

jest.mock('@azure/data-tables', () => {
vitest.mock('@azure/data-tables', async () => {
const listEntities = () => {
const data = getRemoteReport();

Expand All @@ -27,18 +27,18 @@ jest.mock('@azure/data-tables', () => {
};
};

const AzureNamedKeyCredential = jest.fn() as unknown as import('@azure/data-tables').AzureNamedKeyCredential;
const TableClient = jest.fn().mockImplementation(() => ({
const AzureNamedKeyCredential = vitest.fn() as unknown as import('@azure/data-tables').AzureNamedKeyCredential;
const TableClient = vitest.fn().mockImplementation(() => ({
listEntities,
submitTransaction,
})) as unknown as import('@azure/data-tables').TableClient;

const azureTables = await vitest.importActual<typeof import('@azure/data-tables')>('@azure/data-tables');
return {
...azureTables,

AzureNamedKeyCredential,
TableClient,

odata: jest.requireActual('@azure/data-tables').odata,
TableTransaction: jest.requireActual('@azure/data-tables').TableTransaction,
};
});

Expand All @@ -59,7 +59,7 @@ describe('splitArrayToChunks', () => {

describe('uploadReportToRemote', () => {
beforeEach(() => {
jest.clearAllMocks();
vitest.clearAllMocks();
});

beforeAll(() => {
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('uploadReportToRemote', () => {

it('performs no actions if local report is empty', async () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const log = jest.spyOn(console, 'log').mockImplementation(() => {});
const log = vitest.spyOn(console, 'log').mockImplementation(() => {});
await uploadReportToRemote(branchName, commitSHA, []);

expect(log).toHaveBeenCalledTimes(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/monosize-storage-azure/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"types": ["environment", "node"]
},
"include": ["**/*.mts"],
"exclude": ["**/*.test.mts", "jest.config.ts"]
"exclude": ["**/*.test.mts", "vite.config.mts"]
}
5 changes: 2 additions & 3 deletions packages/monosize-storage-azure/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"target": "ESNext",
"types": ["environment", "jest", "node"]
"types": ["vitest/importMeta", "vite/client", "environment", "node", "vitest"]
},
"include": ["**/*.test.mts", "**/*.d.ts", "jest.config.ts"]
"include": ["vite.config.mts", "src/**/*.test.mts", "src/**/*.d.ts"]
}
16 changes: 16 additions & 0 deletions packages/monosize-storage-azure/vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference types='vitest' />
import { defineConfig } from 'vite';

import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';

export default defineConfig({
cacheDir: '../../node_modules/.vite/monosize-storage-azure',
plugins: [nxViteTsPaths()],

test: {
cache: {
dir: '../../node_modules/.vitest',
},
include: ['src/**/*.test.mts'],
},
});
17 changes: 0 additions & 17 deletions packages/monosize-storage-upstash/jest.config.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/monosize-storage-upstash/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
}
},
"test": {
"executor": "@nx/jest:jest",
"executor": "@nx/vite:test",
"outputs": ["{workspaceRoot}/coverage/packages/monosize-storage-upstash"],
"options": {
"jestConfig": "packages/monosize-storage-upstash/jest.config.ts",
"passWithNoTests": true
}
}
Expand Down
11 changes: 5 additions & 6 deletions packages/monosize-storage-upstash/src/getRemoteReport.test.mts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const fetch = jest.fn();

jest.mock('node-fetch', () => ({
default: fetch,
}));
import { beforeEach, describe, it, vitest } from 'vitest';

// import { sampleReport } from '../__fixture__/sampleReport';
// import { getRemoteReport } from './getRemoteReport';

const fetch = vitest.hoisted(() => vitest.fn());
vitest.mock('node-fetch', () => ({ default: fetch }));

function noop() {

Check warning on line 9 in packages/monosize-storage-upstash/src/getRemoteReport.test.mts

View workflow job for this annotation

GitHub Actions / ci

'noop' is defined but never used
/* does nothing */
}

describe('getRemoteReport', () => {
beforeEach(() => {
jest.resetAllMocks();
vitest.resetAllMocks();
});

it('fetches a remote report', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/monosize-storage-upstash/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"types": ["environment", "node"]
},
"include": ["**/*.mts"],
"exclude": ["**/*.test.mts", "jest.config.ts"]
"exclude": ["**/*.test.mts", "vite.config.mts"]
}
5 changes: 2 additions & 3 deletions packages/monosize-storage-upstash/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"target": "ESNext",
"types": ["environment", "jest", "node"]
"types": ["vitest/importMeta", "vite/client", "environment", "node", "vitest"]
},
"include": ["**/*.test.mts", "**/*.d.ts", "jest.config.ts"]
"include": ["vite.config.mts", "src/**/*.test.mts", "src/**/*.d.ts"]
}
Loading
Loading