-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): added npm init parity test
- Loading branch information
1 parent
6298644
commit edfe6df
Showing
2 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
'use strict' | ||
const path = require('path') | ||
const assert = require('assert') | ||
const path = require('node:path') | ||
const assert = require('node:assert') | ||
const fs = require('node:fs/promises') | ||
const { promisify } = require('node:util') | ||
const execFile = promisify(require('node:child_process').execFile) | ||
const { suite, test, before } = require('mocha') | ||
const fixtures = require('fs-test-fixtures') | ||
const createPkgJson = require('..') | ||
|
@@ -79,7 +82,7 @@ suite('create-package-json', () => { | |
assert.strictEqual(pkg.description, '') | ||
assert.strictEqual(pkg.author, 'Test User <[email protected]>') | ||
assert.strictEqual(pkg.repository, undefined) | ||
assert.strictEqual(pkg.keywords, undefined) | ||
assert.deepStrictEqual(pkg.keywords, []) | ||
assert.strictEqual(pkg.license, 'ISC') | ||
assert.strictEqual(pkg.type, 'commonjs') | ||
assert.strictEqual(pkg.main, 'index.js') | ||
|
@@ -248,4 +251,35 @@ suite('create-package-json', () => { | |
assert.deepStrictEqual(pkg.man, './man/foo.1') | ||
}) | ||
}) | ||
|
||
suite('npm init', () => { | ||
test('parity', async () => { | ||
await fix.setup() | ||
try { | ||
await execFile('npm', ['init', '-y'], { | ||
cwd: fix.TMP | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
throw e | ||
} | ||
const npmInitPkg = JSON.parse(await fs.readFile(path.join(fix.TMP, 'package.json'), 'utf8')) | ||
|
||
await fix.setup() | ||
const pkg = await createPackageJson() | ||
|
||
// Should be the same | ||
assert.strictEqual(pkg.name, npmInitPkg.name) | ||
assert.strictEqual(pkg.version, npmInitPkg.version) | ||
assert.strictEqual(pkg.description, npmInitPkg.description) | ||
assert.strictEqual(pkg.main, npmInitPkg.main) | ||
assert.deepStrictEqual(pkg.scripts, npmInitPkg.scripts) | ||
assert.deepStrictEqual(pkg.keywords, npmInitPkg.keywords) | ||
assert.strictEqual(pkg.license, npmInitPkg.license) | ||
|
||
// Should be different | ||
assert.notStrictEqual(pkg.author, npmInitPkg.author, [pkg.author, npmInitPkg.author].toString()) | ||
assert.notStrictEqual(pkg.type, npmInitPkg.type, [pkg.type, npmInitPkg.type].toString()) | ||
}) | ||
}) | ||
}) |