From 74a9b0addc06d2f9745d237322843fd66f79539e Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Mon, 22 Jan 2024 01:22:24 +0000 Subject: [PATCH] chore(project-config): switch to vitest (#9864) Switches our tests in `@redwoodjs/project-config` over to vitest. --- packages/project-config/.babelrc.js | 1 - packages/project-config/jest.config.js | 8 -------- packages/project-config/package.json | 8 ++++---- packages/project-config/src/__tests__/config.test.ts | 2 ++ packages/project-config/src/__tests__/paths.test.ts | 10 ++++++---- packages/project-config/vitest.config.mts | 12 ++++++++++++ yarn.lock | 2 +- 7 files changed, 25 insertions(+), 18 deletions(-) delete mode 100644 packages/project-config/.babelrc.js delete mode 100644 packages/project-config/jest.config.js create mode 100644 packages/project-config/vitest.config.mts diff --git a/packages/project-config/.babelrc.js b/packages/project-config/.babelrc.js deleted file mode 100644 index 3b2c815712d9..000000000000 --- a/packages/project-config/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: '../../babel.config.js' } diff --git a/packages/project-config/jest.config.js b/packages/project-config/jest.config.js deleted file mode 100644 index 02db68858b6d..000000000000 --- a/packages/project-config/jest.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/*.test.[jt]s?(x)'], - testPathIgnorePatterns: ['fixtures', 'dist'], - moduleNameMapper: { - 'src/(.*)': '/src/$1', - }, - testTimeout: 15000, -} diff --git a/packages/project-config/package.json b/packages/project-config/package.json index 20060378e6ce..6d3e4e692316 100644 --- a/packages/project-config/package.json +++ b/packages/project-config/package.json @@ -20,8 +20,8 @@ "build:types": "tsc --build --verbose", "build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", - "test": "jest src", - "test:watch": "run test --watch" + "test": "vitest run src", + "test:watch": "vitest watch src" }, "dependencies": { "@iarna/toml": "2.2.5", @@ -31,9 +31,9 @@ }, "devDependencies": { "esbuild": "0.19.9", - "jest": "29.7.0", "rimraf": "5.0.5", - "typescript": "5.3.3" + "typescript": "5.3.3", + "vitest": "1.2.1" }, "gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1" } diff --git a/packages/project-config/src/__tests__/config.test.ts b/packages/project-config/src/__tests__/config.test.ts index 4f1509757358..c2e458178f20 100644 --- a/packages/project-config/src/__tests__/config.test.ts +++ b/packages/project-config/src/__tests__/config.test.ts @@ -1,5 +1,7 @@ import path from 'path' +import { describe, it, expect } from 'vitest' + import { getConfig, getRawConfig } from '../config' describe('getRawConfig', () => { diff --git a/packages/project-config/src/__tests__/paths.test.ts b/packages/project-config/src/__tests__/paths.test.ts index a0245b0d1fbb..99e34e484f84 100644 --- a/packages/project-config/src/__tests__/paths.test.ts +++ b/packages/project-config/src/__tests__/paths.test.ts @@ -1,5 +1,7 @@ import path from 'path' +import { describe, beforeAll, afterAll, it, expect, test } from 'vitest' + import { processPagesDir, resolveFile, @@ -226,7 +228,7 @@ describe('paths', () => { }) }) - describe('resolveFile', () => { + test('resolveFile', () => { const p = resolveFile(path.join(FIXTURE_BASEDIR, 'web', 'src', 'App')) expect(path.extname(p)).toEqual('.tsx') @@ -547,7 +549,7 @@ describe('paths', () => { }) }) - describe('resolveFile', () => { + test('resolveFile', () => { const p = resolveFile(path.join(FIXTURE_BASEDIR, 'web', 'src', 'App')) expect(path.extname(p)).toEqual('.js') @@ -826,7 +828,7 @@ describe('paths', () => { }) }) - describe('resolveFile', () => { + test('resolveFile', () => { const p = resolveFile(path.join(FIXTURE_BASEDIR, 'web', 'src', 'index')) expect(path.extname(p)).toEqual('.js') @@ -1158,7 +1160,7 @@ describe('paths', () => { }) }) - describe('resolveFile', () => { + test('resolveFile', () => { const p = resolveFile(path.join(FIXTURE_BASEDIR, 'web', 'src', 'Routes')) expect(path.extname(p)).toEqual('.tsx') diff --git a/packages/project-config/vitest.config.mts b/packages/project-config/vitest.config.mts new file mode 100644 index 000000000000..e5f9df88ccb8 --- /dev/null +++ b/packages/project-config/vitest.config.mts @@ -0,0 +1,12 @@ +import { defineConfig, configDefaults } from 'vitest/config' + +export default defineConfig({ + test: { + testTimeout: 15_000, + include: ['**/__tests__/**/*.[jt]s?(x)', '**/*.test.[jt]s?(x)'], + exclude: [...configDefaults.exclude, '**/fixtures', '**/dist'], + alias: { + 'src/(.*)': '/src/$1', + } + }, +}) diff --git a/yarn.lock b/yarn.lock index e3b6932ba660..bc906ddaf8d2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8648,10 +8648,10 @@ __metadata: deepmerge: "npm:4.3.1" esbuild: "npm:0.19.9" fast-glob: "npm:3.3.2" - jest: "npm:29.7.0" rimraf: "npm:5.0.5" string-env-interpolation: "npm:1.0.1" typescript: "npm:5.3.3" + vitest: "npm:1.2.1" languageName: unknown linkType: soft