-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.js
91 lines (84 loc) · 2.87 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict'
const { test, after, before } = require('node:test')
const { join } = require('node:path')
const { mkdtempSync, readdirSync, mkdirSync, rmSync } = require('node:fs')
const { tmpdir } = require('node:os')
const { spawnSync } = require('node:child_process')
const testDir = mkdtempSync(join(tmpdir(), 'create-fastify-test-'))
before(() => {
spawnSync('npm', ['link'], { cwd: __dirname, shell: true })
})
after(() => {
spawnSync('npm', ['unlink', '-g'], { cwd: __dirname, shell: true })
rmSync(testDir, { recursive: true, force: true })
})
test('generates a fastify project in the current folder', (t) => {
t.plan(3)
const projectName = 'create-fastify-test-current'
const dir = join(testDir, projectName)
const opts = { cwd: dir, shell: true }
mkdirSync(dir)
spawnSync('npm', ['link', 'create-fastify'], opts)
spawnSync('npm', ['init', 'fastify'], opts)
t.assert.deepStrictEqual(readdirSync(dir).sort(), [
'.gitignore',
'README.md',
'app.js',
'node_modules', // added by npm link
'package.json',
'plugins',
'routes',
'test'
])
const { name, dependencies } = require(join(dir, 'package.json'))
t.assert.ok(Object.keys(dependencies).includes('fastify'))
t.assert.strictEqual(name, projectName)
})
test('generates a fastify project in the current folder using --integrate', (t) => {
t.plan(3)
const projectName = 'create-fastify-test-integrate'
const dir = join(testDir, projectName)
const opts = { cwd: dir, shell: true }
mkdirSync(dir)
const { stdout: npmVersion } = spawnSync('npm', ['--version'], opts)
spawnSync('npm', ['init', '-y'], opts)
spawnSync('npm', ['link', 'create-fastify'], opts)
if (parseInt(npmVersion.toString().split('.')[0], 10) < 7) {
spawnSync('npm', ['init', 'fastify', '--integrate'], opts)
} else {
spawnSync('npm', ['init', 'fastify', '--', '--integrate'], opts)
}
t.assert.deepStrictEqual(readdirSync(dir).sort(), [
'.gitignore',
'README.md',
'app.js',
'node_modules', // added by npm link
'package.json',
'plugins',
'routes',
'test'
])
const { name, dependencies } = require(join(dir, 'package.json'))
t.assert.ok(Object.keys(dependencies).includes('fastify'))
t.assert.strictEqual(name, projectName)
})
test('generates a fastify project in a new folder', (t) => {
t.plan(3)
const projectName = 'create-fastify-new-dir'
const dir = join(testDir, projectName)
const opts = { cwd: testDir, shell: true }
spawnSync('npm', ['link', 'create-fastify'], opts)
spawnSync('npm', ['init', 'fastify', projectName], opts)
t.assert.deepStrictEqual(readdirSync(dir).sort(), [
'.gitignore',
'README.md',
'app.js',
'package.json',
'plugins',
'routes',
'test'
])
const { name, dependencies } = require(join(dir, 'package.json'))
t.assert.ok(Object.keys(dependencies).includes('fastify'))
t.assert.strictEqual(name, projectName)
})