|
1 | 1 | 'use strict'
|
2 |
| -const path = require('path') |
3 |
| -const assert = require('assert') |
| 2 | +const path = require('node:path') |
| 3 | +const assert = require('node:assert') |
| 4 | +const fs = require('node:fs/promises') |
| 5 | +const { promisify } = require('node:util') |
| 6 | +const execFile = promisify(require('node:child_process').execFile) |
4 | 7 | const { suite, test, before } = require('mocha')
|
5 | 8 | const fixtures = require('fs-test-fixtures')
|
6 | 9 | const createPkgJson = require('..')
|
@@ -79,7 +82,7 @@ suite('create-package-json', () => {
|
79 | 82 | assert.strictEqual(pkg.description, '')
|
80 | 83 | assert.strictEqual(pkg.author, 'Test User <[email protected]>')
|
81 | 84 | assert.strictEqual(pkg.repository, undefined)
|
82 |
| - assert.strictEqual(pkg.keywords, undefined) |
| 85 | + assert.deepStrictEqual(pkg.keywords, []) |
83 | 86 | assert.strictEqual(pkg.license, 'ISC')
|
84 | 87 | assert.strictEqual(pkg.type, 'commonjs')
|
85 | 88 | assert.strictEqual(pkg.main, 'index.js')
|
@@ -248,4 +251,35 @@ suite('create-package-json', () => {
|
248 | 251 | assert.deepStrictEqual(pkg.man, './man/foo.1')
|
249 | 252 | })
|
250 | 253 | })
|
| 254 | + |
| 255 | + suite('npm init', () => { |
| 256 | + test('parity', async () => { |
| 257 | + await fix.setup() |
| 258 | + try { |
| 259 | + await execFile('npm', ['init', '-y'], { |
| 260 | + cwd: fix.TMP |
| 261 | + }) |
| 262 | + } catch (e) { |
| 263 | + console.error(e) |
| 264 | + throw e |
| 265 | + } |
| 266 | + const npmInitPkg = JSON.parse(await fs.readFile(path.join(fix.TMP, 'package.json'), 'utf8')) |
| 267 | + |
| 268 | + await fix.setup() |
| 269 | + const pkg = await createPackageJson() |
| 270 | + |
| 271 | + // Should be the same |
| 272 | + assert.strictEqual(pkg.name, npmInitPkg.name) |
| 273 | + assert.strictEqual(pkg.version, npmInitPkg.version) |
| 274 | + assert.strictEqual(pkg.description, npmInitPkg.description) |
| 275 | + assert.strictEqual(pkg.main, npmInitPkg.main) |
| 276 | + assert.deepStrictEqual(pkg.scripts, npmInitPkg.scripts) |
| 277 | + assert.deepStrictEqual(pkg.keywords, npmInitPkg.keywords) |
| 278 | + assert.strictEqual(pkg.license, npmInitPkg.license) |
| 279 | + |
| 280 | + // Should be different |
| 281 | + assert.notStrictEqual(pkg.author, npmInitPkg.author, JSON.stringify([pkg.author, npmInitPkg.author])) |
| 282 | + assert.notStrictEqual(pkg.type, npmInitPkg.type, JSON.stringify([pkg.type, npmInitPkg.type])) |
| 283 | + }) |
| 284 | + }) |
251 | 285 | })
|
0 commit comments