Skip to content

Commit

Permalink
use vitest instead of mocha
Browse files Browse the repository at this point in the history
uses same build setup as vite; mocha doesn't like ESM
  • Loading branch information
wmertens committed Apr 26, 2024
1 parent f8e30f2 commit e04348d
Show file tree
Hide file tree
Showing 12 changed files with 564 additions and 697 deletions.
1,134 changes: 505 additions & 629 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 3 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"build:analyze": "rimraf build && npm run build:options && ANALYZER=true vite build",
"lint": "cross-env FORCE_COLOR=1 npm-run-all --parallel --aggregate-output lint:*",
"lint:lockfile": "lockfile-lint",
"lint:markdown": "markdownlint \"**/*.md\" --ignore \"**/node_modules/**/*.md\" --ignore build --config .markdownlint.js",
"lint:markdown": "markdownlint \"**/*.md\" --ignore \"**/node_modules/**/*.md\" --ignore build --config .markdownlint.cjs",
"lint:src": "eslint --cache --cache-location node_modules/.cache/.eslintcache --ignore-path .gitignore --report-unused-disable-directives .",
"prepare": "src/scripts/install-hooks",
"prepublishOnly": "npm run build",
"prettier": "prettier . --check",
"test": "npm run test:unit && npm run test:e2e",
"test:bun": "test/bun-install.sh && mocha test/bun",
"test:unit": "mocha test test/package-managers/*",
"test:unit": "vitest test test/package-managers/*",
"test:e2e": "./test/e2e.sh",
"ncu": "node build/cli.js"
},
Expand Down Expand Up @@ -68,7 +68,6 @@
"@types/json-parse-helpfulerror": "^1.0.3",
"@types/jsonlines": "^0.1.5",
"@types/lodash": "^4.17.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.30",
"@types/npm-registry-fetch": "^8.0.7",
"@types/parse-github-url": "^1.0.3",
Expand Down Expand Up @@ -111,7 +110,6 @@
"lockfile-lint": "^4.13.2",
"lodash": "^4.17.21",
"markdownlint-cli": "^0.39.0",
"mocha": "^10.4.0",
"npm-registry-fetch": "^16.1.0",
"npm-run-all": "^4.1.5",
"p-map": "^4.0.0",
Expand All @@ -133,7 +131,6 @@
"spawn-please": "^3.0.0",
"strip-ansi": "^7.1.0",
"strip-json-comments": "^5.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.3",
"typescript-json-schema": "^0.63.0",
"untildify": "^4.0.0",
Expand All @@ -143,6 +140,7 @@
"vite-bundle-analyzer": "^0.9.3",
"vite-node": "^1.4.0",
"vite-plugin-dts": "^3.8.0",
"vitest": "^1.4.0",
"yarn": "^1.22.22"
},
"files": [
Expand All @@ -161,19 +159,5 @@
"empty-hostname": false,
"type": "npm ",
"path": "package-lock.json"
},
"mocha": {
"check-leaks": true,
"extension": [
"test.ts"
],
"require": [
"source-map-support/register",
"ts-node/register"
],
"timeout": 60000,
"trace-deprecation": true,
"trace-warnings": true,
"use_strict": true
}
}
8 changes: 3 additions & 5 deletions test/bun/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ describe('bun', function () {
version!.should.equal('2.0.0')
})

describe('doctor', function () {
this.timeout(3 * 60 * 1000)

describe('doctor', { timeout: 3 * 60 * 1000 }, function () {
let stub: { restore: () => void }
before(() => (stub = stubVersions(mockNpmVersions, { spawn: true })))
after(() => stub.restore())
beforeEach(() => (stub = stubVersions(mockNpmVersions, { spawn: true })))
afterEach(() => stub.restore())

testPass({ packageManager: 'bun' })
testFail({ packageManager: 'bun' })
Expand Down
20 changes: 10 additions & 10 deletions test/deep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ const setupDeepTest = async () => {
return tempDir
}

describe('--deep', function () {
this.timeout(60000)

describe('--deep', { timeout: 60000 }, function () {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('do not allow --packageFile and --deep together', async () => {
await ncu({ packageFile: './package.json', deep: true }).should.eventually.be.rejectedWith('Cannot specify both')
Expand Down Expand Up @@ -121,14 +121,14 @@ describe('--deep', function () {
})
})

describe('--deep with nested ncurc files', function () {
describe('--deep with nested ncurc files', { timeout: 60000 }, function () {
const cwd = path.join(__dirname, 'test-data/deep-ncurc')

this.timeout(60000)

let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('use ncurc of nested packages', async () => {
const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--deep'], {}, { cwd })
Expand Down
12 changes: 6 additions & 6 deletions test/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const ncu = async (
return stdout
}

describe('doctor', function () {
// 3 min timeout
this.timeout(3 * 60 * 1000)

// 3 min timeout
describe('doctor', { timeout: 3 * 60 * 1000 }, function () {
let stub: { restore: () => void }
before(() => (stub = stubVersions(mockNpmVersions, { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions(mockNpmVersions, { spawn: true })
})
afterEach(() => stub.restore())

describe('npm', () => {
it('print instructions when -u is not specified', async () => {
Expand Down
18 changes: 12 additions & 6 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const bin = path.join(__dirname, '../build/cli.js')
describe('filter', () => {
describe('module', () => {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9')))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9')
})
afterEach(() => stub.restore())

it('filter by package name with one arg', async () => {
const upgraded = (await ncu({
Expand Down Expand Up @@ -203,8 +205,10 @@ describe('filter', () => {

describe('cli', () => {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('filter by package name with --filter', async () => {
const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '--filter', 'express'], {
Expand Down Expand Up @@ -296,8 +300,10 @@ describe('filter', () => {
describe('reject', () => {
describe('cli', () => {
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('reject by package name with --reject', async () => {
const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '--reject', 'chalk'], {
Expand Down
4 changes: 2 additions & 2 deletions test/filterVersion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const bin = path.join(__dirname, '../build/cli.js')
describe('filterVersion', () => {
describe('module', () => {
let stub: { restore: () => void }
before(() => {
beforeEach(() => {
stub = stubVersions({
'ncu-test-v2': '2.0.0',
'ncu-test-return-version': '2.0.0',
})
})
after(() => {
afterEach(() => {
stub.restore()
})

Expand Down
4 changes: 2 additions & 2 deletions test/interactive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const bin = path.join(__dirname, '../build/cli.js')

describe('--interactive', () => {
let stub: { restore: () => void }
before(() => {
beforeEach(() => {
stub = stubVersions(
{
'ncu-test-v2': '2.0.0',
Expand All @@ -22,7 +22,7 @@ describe('--interactive', () => {
{ spawn: true },
)
})
after(() => {
afterEach(() => {
stub.restore()
})

Expand Down
6 changes: 4 additions & 2 deletions test/rc-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const bin = path.join(__dirname, '../build/cli.js')
describe('rc-config', () => {
// before/after must be placed within the describe block, otherwise they will apply to tests in other files
let stub: { restore: () => void }
before(() => (stub = stubVersions('99.9.9', { spawn: true })))
after(() => stub.restore())
beforeEach(() => {
stub = stubVersions('99.9.9', { spawn: true })
})
afterEach(() => stub.restore())

it('print rcConfigPath when there is a non-empty rc config file', async () => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
Expand Down
20 changes: 6 additions & 14 deletions test/workspaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let stub: { restore: () => void }

describe('workspaces', () => {
describe('stubbed', () => {
before(() => {
beforeEach(() => {
stub = stubVersions(
{
'ncu-test-v2': '2.0.0',
Expand All @@ -122,13 +122,11 @@ describe('workspaces', () => {
{ spawn: true },
)
})
after(() => {
afterEach(() => {
stub.restore()
})

describe('--workspaces', function () {
this.timeout(60000)

describe('--workspaces', { timeout: 60000 }, function () {
it('do not allow --workspaces and --deep together', async () => {
await ncu({ workspaces: true, deep: true }).should.eventually.be.rejectedWith('Cannot specify both')
})
Expand Down Expand Up @@ -256,9 +254,7 @@ describe('workspaces', () => {
})
})

describe('--workspace', function () {
this.timeout(60000)

describe('--workspace', { timeout: 60000 }, function () {
it('do not allow --workspace and --deep together', async () => {
await ncu({ workspace: ['a'], deep: true }).should.eventually.be.rejectedWith('Cannot specify both')
})
Expand Down Expand Up @@ -360,9 +356,7 @@ describe('workspaces', () => {
})
})

describe('--root/--no-root', function () {
this.timeout(60000)

describe('--root/--no-root', { timeout: 60000 }, function () {
it('update root project by default', async () => {
const tempDir = await setup()
try {
Expand Down Expand Up @@ -451,9 +445,7 @@ describe('workspaces', () => {
})
})

describe('--workspace should include --root by default', function () {
this.timeout(60000)

describe('--workspace should include --root by default', { timeout: 60000 }, function () {
it('update root project and single workspace', async () => {
const tempDir = await setup()
try {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es2021"
"target": "es2021",
"types": ["node", "vitest/globals"]
}
}
10 changes: 9 additions & 1 deletion vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default defineConfig(({ mode }) => ({
rollupTypes: true,
include: ['src'],
}),
nodeExternals(),
process.env.ANALYZER && analyzer(),
mode !== 'test' && nodeExternals(),
{
name: 'fixBinPerm',
writeBundle: () => {
Expand All @@ -40,4 +40,12 @@ export default defineConfig(({ mode }) => ({
outDir: 'build',
minify: mode === 'production' && 'esbuild',
},
test: {
globals: true,
typecheck: { enabled: true },
testOptions: {
files: ['test/**/*.test.ts'],
},
pool: 'forks',
},
}))

0 comments on commit e04348d

Please sign in to comment.