Skip to content

Commit

Permalink
Move to Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jan 28, 2024
1 parent e478840 commit 0a5670c
Show file tree
Hide file tree
Showing 14 changed files with 1,406 additions and 477 deletions.
File renamed without changes.
1,812 changes: 1,364 additions & 448 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions package.json
Expand Up @@ -11,6 +11,7 @@
"email": "hello@feathers.cloud",
"url": "https://feathers.cloud"
},
"type": "module",
"license": "MIT",
"funding": {
"type": "github",
Expand All @@ -33,12 +34,14 @@
"eslint": "eslint \"packages/**/*.ts\" --fix",
"lint": "npm run prettier && npm run eslint",
"update-dependencies": "ncu -u && lerna exec -- ncu -u",
"test": "npm run lint && c8 npm test --workspaces"
"dev": "vitest watch --coverage",
"vitest": "vitest run --coverage",
"test": "npm run lint && npm run compile --workspaces && npm run vitest"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"c8": "^9.0.0",
"@vitest/coverage-v8": "^1.2.2",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
Expand All @@ -47,6 +50,7 @@
"lerna": "^8.0.1",
"npm-check-updates": "^16.14.12",
"prettier": "^3.1.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^1.2.2"
}
}
3 changes: 1 addition & 2 deletions packages/pinion/package.json
Expand Up @@ -45,8 +45,7 @@
],
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"test": "npm run compile && shx rm -rf test/tmp && node --import tsx --test test/**.test.ts"
"compile": "shx rm -rf lib/ && tsc"
},
"directories": {
"lib": "lib"
Expand Down
15 changes: 8 additions & 7 deletions packages/pinion/src/tasks/prompt.ts
Expand Up @@ -26,13 +26,14 @@ export type AnswerType<Q extends Question> = Q extends { type: 'input' }
/**
* Get the types for the answers from a prompt() function
*/
export type AnswerTypes<Q extends QuestionCollection> = Q extends ReadonlyArray<Question & { name: string }>
? { [K in Q[number] as K['name']]: AnswerType<K> }
: Q extends { [key: string]: Question }
? {
[K in keyof Q]: AnswerType<Q[K]>
}
: unknown
export type AnswerTypes<Q extends QuestionCollection> =
Q extends ReadonlyArray<Question & { name: string }>
? { [K in Q[number] as K['name']]: AnswerType<K> }
: Q extends { [key: string]: Question }
? {
[K in keyof Q]: AnswerType<Q[K]>
}
: unknown

/**
* Show prompts using Inquirer
Expand Down
12 changes: 3 additions & 9 deletions packages/pinion/test/cli.test.ts
@@ -1,24 +1,18 @@
import { describe, it } from 'node:test'
import { describe, it } from 'vitest'
import assert from 'assert'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import { cli } from '../lib/index.js'
import { cli } from '../src/index.js'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

describe('@featherscloud/pinion/cli', () => {
it('runs the CLI with a generator and command line arguments', async () => {
const oldCwd = process.cwd()

process.chdir(__dirname)

const ctx = await cli(['templates/cli.ts', '--name', 'testing'])
const ctx = await cli(['packages/pinion/test/templates/cli.ts', '--name', 'testing'])

assert.ok(ctx.noop)
assert.strictEqual(ctx.name, 'testing')

process.chdir(oldCwd)
})

it('errors without generator file', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/pinion/test/index.test.ts
@@ -1,9 +1,9 @@
import { describe, it } from 'node:test'
import { describe, it } from 'vitest'
import path from 'path'
import { fileURLToPath } from 'url'
import { readFile } from 'fs/promises'
import assert from 'assert'
import { getContext, PinionContext, runModule } from '../lib/index.js'
import { getContext, PinionContext, runModule } from '../src/index.js'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
Expand Down
2 changes: 1 addition & 1 deletion packages/pinion/test/templates/cli.ts
@@ -1,4 +1,4 @@
import { PinionContext, commander, Command } from '../../lib/index.js'
import { PinionContext, commander, Command } from '../../src/index.js'

interface Context extends PinionContext {
name: string
Expand Down
2 changes: 1 addition & 1 deletion packages/pinion/test/templates/json.tpl.ts
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from 'url'
import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
import { loadJSON, fromFile, toFile, writeJSON, mergeJSON, PinionContext } from '../../lib/index.js'
import { loadJSON, fromFile, toFile, writeJSON, mergeJSON, PinionContext } from '../../src/index.js'

export const generate = (ctx: PinionContext) =>
Promise.resolve(ctx)
Expand Down
2 changes: 1 addition & 1 deletion packages/pinion/test/templates/noop.ts
@@ -1,3 +1,3 @@
import { PinionContext } from '../../lib/index.js'
import { PinionContext } from '../../src/index.js'

export const generate = (ctx: PinionContext) => Promise.resolve(ctx)
2 changes: 1 addition & 1 deletion packages/pinion/test/templates/pinion.ts
Expand Up @@ -15,7 +15,7 @@ import {
before,
exec,
copyFiles
} from '../../lib/index.js'
} from '../../src/index.js'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
Expand Down
4 changes: 2 additions & 2 deletions packages/pinion/test/utils.test.ts
@@ -1,7 +1,7 @@
import { describe, it } from 'node:test'
import { describe, it } from 'vitest'
import path from 'path'
import assert from 'assert'
import { merge, listAllFiles, loadModule, listFiles } from '../lib/utils.js'
import { merge, listAllFiles, loadModule, listFiles } from '../src/utils.js'
import { fileURLToPath } from 'url'

const __filename = fileURLToPath(import.meta.url)
Expand Down
11 changes: 11 additions & 0 deletions vitest.config.ts
@@ -0,0 +1,11 @@
// vitest.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
coverage: {
provider: 'v8',
include: ['packages/*/src/**/*.ts']
}
}
})
4 changes: 4 additions & 0 deletions vitest.workspace.ts
@@ -0,0 +1,4 @@
import { defineWorkspace } from 'vitest/config'

// defineWorkspace provides a nice type hinting DX
export default defineWorkspace(['packages/*'])

0 comments on commit 0a5670c

Please sign in to comment.