Skip to content

Commit

Permalink
Deprecate jest in favor of vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed May 21, 2024
1 parent cbb78b3 commit 037567c
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 3,338 deletions.
10 changes: 0 additions & 10 deletions packages/create/jest.config.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "pnpm build --watch",
"lint": "eslint ./src",
"type-check": "tsc --noEmit",
"test": "jest"
"test": "vitest"
},
"license": "MIT",
"description": "Initialize a new Master CSS project",
Expand Down Expand Up @@ -37,6 +37,7 @@
"provenance": true
},
"dependencies": {
"@master/css": "2.0.0-rc.38",
"@techor/fs": "^3.0.22",
"@techor/log": "^3.0.22",
"commander": "^12.0.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/create/tests/cjs/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { test, it, expect } from 'vitest'
import { execSync } from 'child_process'
import { join } from 'node:path'
import { readFileSync } from 'node:fs'
import { rm } from '@master/css-shared/utils/fs'

it('init cjs', () => {
it('init cjs', async () => {
rm(join(__dirname, 'master.css.js'))
execSync('tsx ../../src/bin', { cwd: __dirname })
expect(readFileSync(join(__dirname, 'master.css.js'), 'utf-8')).toEqual(require('../../src/master.css.js.js').default)
const config = (await import('../../src/master.css.js.js')).default
expect(readFileSync(join(__dirname, 'master.css.js'), 'utf-8')).toEqual(config)
})
6 changes: 4 additions & 2 deletions packages/create/tests/esm/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { test, it, expect } from 'vitest'
import { execSync } from 'child_process'
import { join } from 'node:path'
import { readFileSync } from 'node:fs'
import { rm } from '@master/css-shared/utils/fs'

it('init (type="module")', () => {
it('init (type="module")', async () => {
rm(join(__dirname, 'master.css.mjs'))
execSync('tsx ../../src/bin', { cwd: __dirname })
expect(readFileSync(join(__dirname, 'master.css.mjs'), 'utf-8')).toEqual(require('../../src/master.css.mjs.js').default)
const config = (await import('../../src/master.css.mjs.js')).default
expect(readFileSync(join(__dirname, 'master.css.mjs'), 'utf-8')).toEqual(config)
})
9 changes: 5 additions & 4 deletions packages/create/tests/new/test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { test, it, expect } from 'vitest'
import { execSync } from 'child_process'
import { rm } from '@master/css-shared/utils/fs'
import { join } from 'node:path'
import { existsSync, readFileSync } from 'node:fs'

it('creates a new app', () => {
rm(join(__dirname, 'my-app'))
execSync('tsx ../../src/bin my-app', { cwd: __dirname })
expect(existsSync(join(__dirname, 'my-app/package.json'))).toBe(true)
rm(join(__dirname, 'dist'))
execSync('tsx ../../src/bin dist', { cwd: __dirname })
expect(existsSync(join(__dirname, 'dist/package.json'))).toBe(true)
})

it('should install the remote dependencies', () => {
expect(readFileSync(join(__dirname, 'my-app/package.json')).toString()).not.toContain('workspace:^')
expect(readFileSync(join(__dirname, 'dist/package.json')).toString()).not.toContain('workspace:^')
})
1 change: 1 addition & 0 deletions packages/create/tests/nextjs/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, it, expect } from 'vitest'
import { execSync } from 'child_process'
import { rm } from '@master/css-shared/utils/fs'
import { join } from 'node:path'
Expand Down
6 changes: 4 additions & 2 deletions packages/create/tests/ts/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { test, it, expect } from 'vitest'
import { execSync } from 'child_process'
import { join } from 'node:path'
import { readFileSync } from 'node:fs'
import { rm } from '@master/css-shared/utils/fs'

it('init by tsconfig.json', () => {
it('init by tsconfig.json', async () => {
rm(join(__dirname, 'master.css.ts'))
execSync('tsx ../../src/bin', { cwd: __dirname })
expect(readFileSync(join(__dirname, 'master.css.ts'), 'utf-8')).toEqual(require('../../src/master.css.ts.js').default)
const config = (await import('../../src/master.css.ts.js')).default
expect(readFileSync(join(__dirname, 'master.css.ts'), 'utf-8')).toEqual(config)
})
24 changes: 15 additions & 9 deletions packages/create/tests/with-deps/test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { test, it, expect, beforeAll } from 'vitest'
import { execSync } from 'child_process'
import { join } from 'node:path'
import { existsSync, writeFileSync } from 'node:fs'
import { rm, mkdir } from 'shared/utils/fs'

writeFileSync(join(__dirname, 'package.json'), JSON.stringify({
'name': 'with-package-json.test',
'private': true,
'dependencies': {
'@master/css': 'latest'
}
}))
beforeAll(() => {
rm(join(__dirname, 'dist'))
mkdir(join(__dirname, 'dist'))
writeFileSync(join(__dirname, './dist/package.json'), JSON.stringify({
'name': 'with-package-json.test',
'private': true,
'dependencies': {
'@master/css': 'latest'
}
}))
})

it('init', () => {
execSync('tsx ../../src/bin', { cwd: __dirname })
expect(existsSync(join(__dirname, 'node_modules'))).toBeFalsy()
execSync('tsx ../../../src/bin', { cwd: join(__dirname, 'dist')})
expect(existsSync(join(__dirname, './dist/node_modules'))).toBeFalsy()
})
18 changes: 12 additions & 6 deletions packages/create/tests/with-no-deps/test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { test, it, expect, beforeAll } from 'vitest'
import { execSync } from 'child_process'
import { join } from 'node:path'
import { readFileSync, writeFileSync } from 'node:fs'
import { rm, mkdir } from 'shared/utils/fs'

writeFileSync(join(__dirname, 'package.json'), JSON.stringify({
'name': 'with-package-json.test',
'private': true
}))
beforeAll(() => {
rm(join(__dirname, 'dist'))
mkdir(join(__dirname, 'dist'))
writeFileSync(join(__dirname, './dist/package.json'), JSON.stringify({
'name': 'with-package-json.test',
'private': true
}))
})

it('init', () => {
// MacOS and Windows -> error https://registry.yarnpkg.com/@master/css/-/css-2.0.0-rc.21.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOENT: no such file or directory, chmod '/Users/runner/Library/Caches/Yarn/v6/npm-@master-css-2.0.0-rc.21-95d553b31c3370f41a9c60815841f3c359f95bcc-integrity/node_modules/@master/css/README.md'"
if (!process.env.CI || process.env.RUNNER_OS === 'Linux') {
execSync('tsx ../../src/bin', { cwd: __dirname })
expect(JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf-8')).dependencies['@master/css']).toBeDefined()
execSync('tsx ../../../src/bin', { cwd: join(__dirname, 'dist')})
expect(JSON.parse(readFileSync(join(__dirname, './dist/package.json'), 'utf-8')).dependencies['@master/css']).toBeDefined()
}
})
4 changes: 4 additions & 0 deletions packages/create/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from 'vitest/config'
import config from '../../shared/vitest.config'

export default defineConfig(config)
10 changes: 0 additions & 10 deletions packages/validator/jest.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dev": "pnpm build --watch",
"lint": "eslint ./src",
"type-check": "tsc --noEmit",
"test": "jest --forceExit --detectOpenHandles"
"test": "vitest"
},
"license": "MIT",
"description": "Validate Master CSS syntax",
Expand Down
1 change: 1 addition & 0 deletions packages/validator/tests/css.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, it, expect } from 'vitest'
import validateCSS from '../src/validate-css'

it('selector', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/validator/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, it, expect } from 'vitest'
import { generateValidRules } from '../src'
import expectClassWithErrors from './utils/expect-class-with-errors'
import expectClassWithoutErrors from './utils/expect-class-without-errors'
Expand Down
1 change: 1 addition & 0 deletions packages/validator/tests/utils/expect-class-invalid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from 'vitest'
import { isClassValid } from '../../src'

export default function expectClassInvalid(syntax: string) {
Expand Down
3 changes: 2 additions & 1 deletion packages/validator/tests/utils/expect-class-valid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isClassValid, validate } from '../../src'
import { expect } from 'vitest'
import { validate } from '../../src'

export default function expectClassValid(syntax: string) {
const errors = validate(syntax).errors
Expand Down
1 change: 1 addition & 0 deletions packages/validator/tests/utils/expect-class-with-errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from 'vitest'
import { validate } from '../../src'

export default function expectClassWithErrors(syntax: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from 'vitest'
import { validate } from '../../src'

export default function expectClassWithoutErrors(syntax: string) {
Expand Down
4 changes: 4 additions & 0 deletions packages/validator/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from 'vitest/config'
import config from '../../shared/vitest.config'

export default defineConfig(config)
Loading

0 comments on commit 037567c

Please sign in to comment.