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 4, 2024
1 parent 01680c6 commit 74b5c39
Show file tree
Hide file tree
Showing 11 changed files with 548 additions and 699 deletions.
1,131 changes: 494 additions & 637 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 2 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"prepublishOnly": "npm run build",
"prettier": "prettier . --check",
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "mocha test test/package-managers/*",
"test:unit": "vitest test/package-managers/*",
"test:e2e": "./test/e2e.sh",
"ncu": "node build/cli.js"
},
Expand Down Expand Up @@ -67,7 +67,6 @@
"@types/jsonlines": "^0.1.5",
"@types/lodash": "^4.17.0",
"@types/make-fetch-happen": "^10.0.4",
"@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 @@ -109,7 +108,6 @@
"lodash": "^4.17.21",
"make-fetch-happen": "^13.0.0",
"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 @@ -130,7 +128,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 @@ -139,6 +136,7 @@
"vite": "^5.2.6",
"vite-node": "^1.4.0",
"vite-plugin-dts": "^3.8.0",
"vitest": "^1.4.0",
"yarn": "^1.22.22"
},
"files": [
Expand All @@ -157,19 +155,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
}
}
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 @@ -174,13 +174,13 @@ const testFail = ({ packageManager }: { packageManager: PackageManagerName }) =>
})
}

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"]
}
}
9 changes: 8 additions & 1 deletion vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default defineConfig(({ mode }) => ({
rollupTypes: true,
include: ['src'],
}),
nodeExternals(),
mode !== 'test' && nodeExternals(),
{
name: 'fixBinPerm',
writeBundle: () => {
Expand All @@ -38,4 +38,11 @@ export default defineConfig(({ mode }) => ({
outDir: 'build',
minify: mode === 'production' && 'esbuild',
},
test: {
globals: true,
typecheck: { enabled: true },
testOptions: {
files: ['test/**/*.test.ts'],
},
},
}))

0 comments on commit 74b5c39

Please sign in to comment.