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

update vitest #879

Merged
merged 11 commits into from
Apr 6, 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
15 changes: 9 additions & 6 deletions .github/workflows/test-multiple-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [cjs, umd] # [cjs, esm, umd, system]
build: [cjs, esm]
env: [development, production]
steps:
- uses: actions/checkout@v2
Expand All @@ -37,27 +37,30 @@ jobs:
run: |
sed -i~ "s/it[.a-zA-Z]*('\[PRD-ONLY\]/it('/" tests/*.ts tests/*.tsx
sed -i~ "s/it[.a-zA-Z]*('\[DEV-ONLY\]/it.skip('/" tests/*.ts tests/*.tsx
sed -i~ "s/describe(/describe.skip(/" tests/memoryleaks.test.ts # FIXME why it doesn't work in production mode?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed. Help wanted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #880.

- name: Patch for CJS
if: ${{ matrix.build == 'cjs' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\1.js/" package.json
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\1.js')/" vitest.config.ts
sed -i~ "s/\"valtio\/vanilla\"/\"..\/..\/..\/dist\/vanilla.js\"/" node_modules/derive-valtio/dist/index.umd.js
- name: Patch for ESM
if: ${{ matrix.build == 'esm' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/esm\1.js" package.json
sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests.ts tests/*.tsx
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/esm\1.mjs')/" vitest.config.ts
sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests/*.tsx
env:
NODE_ENV: ${{ matrix.env }}
- name: Patch for UMD
if: ${{ matrix.build == 'umd' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/umd\1.${NODE_ENV}.js/" package.json
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/umd\1.${NODE_ENV}.js')/" vitest.config.ts
sed -i~ "s/\"valtio\/vanilla\"/\"..\/..\/..\/dist\/umd\/vanilla.${NODE_ENV}.js\"/" node_modules/derive-valtio/dist/index.umd.js
env:
NODE_ENV: ${{ matrix.env }}
- name: Patch for SystemJS
if: ${{ matrix.build == 'system' }}
run: |
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/system\1.${NODE_ENV}.js/" package.json
sed -i~ "s/resolve('\.\/src\(.*\)\.ts')/resolve('\.\/dist\/system\1.${NODE_ENV}.js')/" vitest.config.ts
env:
NODE_ENV: ${{ matrix.env }}
- name: Test ${{ matrix.build }} ${{ matrix.env }}
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ jobs:
run: |
yarn add -D typescript@${{ matrix.typescript }}
rm node_modules/parse5/dist/*.d.ts
- name: Patch testing setup for Old TS
if: ${{ matrix.typescript == '4.4.4' || matrix.typescript == '4.3.5' || matrix.typescript == '4.2.3' || matrix.typescript == '4.1.5' || matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
rm node_modules/@vitest/expect/dist/*.d.ts
echo "declare module '@vitest/expect'" >> ./src/types.d.ts
rm node_modules/@vitest/runner/dist/*.d.ts
echo "declare module '@vitest/runner'" >> ./src/types.d.ts
rm node_modules/@vitest/spy/dist/*.d.ts
echo "declare module '@vitest/spy'" >> ./src/types.d.ts
rm node_modules/@vitest/utils/dist/*.d.ts
echo "declare module '@vitest/utils'" >> ./src/types.d.ts
rm node_modules/vite-node/dist/*.d.ts
echo "declare module 'vite-node'" >> ./src/types.d.ts
rm node_modules/vitest/dist/*.d.ts
echo "declare module 'vitest'" >> ./src/types.d.ts
- name: Patch testing setup for older TS
if: ${{ matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
"@types/use-sync-external-store": "^0.0.6",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@vitest/coverage-v8": "0.33.0",
"@vitest/ui": "0.33.0",
"@vitest/coverage-v8": "^1.4.0",
"@vitest/ui": "^1.4.0",
"aslemammad-vite-plugin-macro": "^1.0.0",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-tester": "10.1.0",
Expand Down Expand Up @@ -161,7 +161,7 @@
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"vitest": "0.33.0"
"vitest": "^1.4.0"
},
"resolutions": {
"@types/react": "18.2.56"
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/macro-vite.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`basic 1`] = `
"import { useSnapshot as _useSnapshot } from \\"valtio\\";
"import { useSnapshot as _useSnapshot } from "valtio";


const Component = () => {const valtio_macro_snap_state = _useSnapshot(
Expand All @@ -16,7 +16,7 @@ const Component = () => {const valtio_macro_snap_state = _useSnapshot(
`;

exports[`complex 1`] = `
"import { useSnapshot as _useSnapshot } from \\"valtio\\";
"import { useSnapshot as _useSnapshot } from "valtio";


const Component = () => {const valtio_macro_snap_state = _useSnapshot(
Expand Down
6 changes: 3 additions & 3 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path'
import { resolve } from 'path'
// eslint-disable-next-line import/extensions
import { defineConfig } from 'vitest/config'

export default defineConfig({
resolve: {
alias: [
{ find: /^valtio$/, replacement: path.resolve('./src/index.ts') },
{ find: /^valtio(.*)$/, replacement: path.resolve('./src/$1.ts') },
{ find: /^valtio$/, replacement: resolve('./src/index.ts') },
{ find: /^valtio(.*)$/, replacement: resolve('./src/$1.ts') },
],
},
test: {
Expand Down
Loading
Loading