Skip to content

Commit eecd2b2

Browse files
committed
Merge branch 'master' of github.com:fastify/fastify-cli
2 parents e4860ce + 1843208 commit eecd2b2

File tree

8 files changed

+29
-32
lines changed

8 files changed

+29
-32
lines changed

lib/watch/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ const watch = function (args, ignoreWatch, verboseWatch) {
4848
})
4949

5050
_child.on('exit', function (code, signal) {
51-
if (!code) {
52-
stop()
53-
}
5451
if (childs.length === 0 && !allStop) {
5552
childs.push(run('restart'))
5653
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"lint": "standard",
1111
"lint:fix": "standard --fix",
12-
"unit": "tap \"test/**/*.test.{js,ts}\" \"templates/**/*.test.{js,ts}\"",
12+
"unit": "tap \"test/**/*.test.{js,ts}\" \"templates/**/*.test.{js,ts}\" --timeout 120",
1313
"pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'",
1414
"test": "npm run lint && npm run unit && npm run test:typescript",
1515
"test:typescript": "tsd templates/plugin && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist"

templates/app/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Getting Started with Fastify-CLI [Fastify-CLI](https://www.npmjs.com/package/fastify-cli)
1+
# Getting Started with [Fastify-CLI](https://www.npmjs.com/package/fastify-cli)
22
This project was bootstrapped with Fastify-CLI.
33

44
## Available Scripts

test/generate-plugin.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const { generate, pluginTemplate } = require('../generate-plugin')
1717
const workdir = path.join(__dirname, 'workdir')
1818
const templateDir = path.join(__dirname, '..', 'templates', 'plugin')
1919
const cliPkg = require('../package')
20-
const { exec } = require('child_process')
20+
const { exec, execSync } = require('child_process')
2121
const minimatch = require('minimatch')
2222
const strip = require('strip-ansi')
2323
const expected = {}
24+
const initVersion = execSync('npm get init-version').toString().trim()
2425

2526
;(function (cb) {
2627
const files = []
@@ -121,7 +122,7 @@ function define (t) {
121122
t.equal(pkg.main, 'index.js')
122123
t.equal(pkg.types, 'index.d.ts')
123124
// we are not checking author because it depends on global npm configs
124-
t.equal(pkg.version, '1.0.0')
125+
t.equal(pkg.version, initVersion)
125126
t.equal(pkg.description, '')
126127
t.ok(pkg.license === 'MIT')
127128
t.equal(pkg.scripts.lint, 'standard && npm run lint:typescript')

test/generate-typescript.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const { generate, typescriptTemplate } = require('../generate')
1717
const workdir = path.join(__dirname, 'workdir')
1818
const appTemplateDir = path.join(__dirname, '..', 'templates', 'app-ts')
1919
const cliPkg = require('../package')
20-
const { exec } = require('child_process')
20+
const { exec, execSync } = require('child_process')
2121
const minimatch = require('minimatch')
2222
const strip = require('strip-ansi')
2323
const expected = {}
24+
const initVersion = execSync('npm get init-version').toString().trim()
2425

2526
;(function (cb) {
2627
const files = []
@@ -120,7 +121,7 @@ function define (t) {
120121
const pkg = JSON.parse(data)
121122
t.equal(pkg.name, 'workdir')
122123
// we are not checking author because it depends on global npm configs
123-
t.equal(pkg.version, '1.0.0')
124+
t.equal(pkg.version, initVersion)
124125
t.equal(pkg.description, 'This project was bootstrapped with Fastify-CLI.')
125126
// by default this will be ISC but since we have a MIT licensed pkg file in upper dir, npm will set the license to MIT in this case
126127
// so for local tests we need to accept MIT as well

test/generate.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ const { generate, javascriptTemplate } = require('../generate')
2020
const workdir = path.join(__dirname, 'workdir')
2121
const appTemplateDir = path.join(__dirname, '..', 'templates', 'app')
2222
const cliPkg = require('../package')
23-
const { exec } = require('child_process')
23+
const { exec, execSync } = require('child_process')
2424
const pExec = promisify(exec)
2525
const pUnlink = promisify(unlink)
2626
const minimatch = require('minimatch')
2727
const strip = require('strip-ansi')
2828
const expected = {}
29+
const initVersion = execSync('npm get init-version').toString().trim()
2930

3031
;(function (cb) {
3132
const files = []
@@ -154,7 +155,7 @@ function define (t) {
154155
const pkg = JSON.parse(data)
155156
t.equal(pkg.name, pkgName)
156157
// we are not checking author because it depends on global npm configs
157-
t.equal(pkg.version, '1.0.0')
158+
t.equal(pkg.version, initVersion)
158159
t.equal(pkg.description, 'This project was bootstrapped with Fastify-CLI.')
159160
// by default this will be ISC but since we have a MIT licensed pkg file in upper dir, npm will set the license to MIT in this case
160161
// so for local tests we need to accept MIT as well

test/print-routes.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('should print routes', async t => {
1919

2020
await fastify.close()
2121
t.ok(spy.called)
22-
t.ok(spy.calledWithMatch('debug', '└── / (GET)\n / (POST)\n'))
22+
t.same(spy.args, [['debug', '└── / (GET)\n / (HEAD)\n / (POST)\n']])
2323
})
2424

2525
test('should print routes via cli', async t => {
@@ -32,7 +32,7 @@ test('should print routes via cli', async t => {
3232
await command.cli(['./examples/plugin.js'])
3333

3434
t.ok(spy.called)
35-
t.ok(spy.calledWithMatch('debug', '└── / (GET)\n / (POST)\n'))
35+
t.same(spy.args, [['debug', '└── / (GET)\n / (HEAD)\n / (POST)\n']])
3636
})
3737

3838
test('should warn on file not found', t => {
@@ -109,5 +109,5 @@ test('should print routes of server with an async/await plugin', async t => {
109109

110110
await fastify.close()
111111
t.ok(spy.called)
112-
t.ok(spy.calledWithMatch('debug', '└── / (GET)\n'))
112+
t.same(spy.args, [['debug', '└── / (GET)\n / (HEAD)\n']])
113113
})

test/start.test.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ test('should error with a good timeout value', async t => {
251251
}
252252
})
253253

254+
const port = getPort()
255+
254256
try {
255-
const argv = ['-p', '3040', '-T', '100', './test/data/timeout-plugin.js']
257+
const argv = ['-p', port, '-T', '100', './test/data/timeout-plugin.js']
256258
await start.start(argv)
257259
} catch (err) {
258260
t.equal(err.code, 'AVV_ERR_READY_TIMEOUT')
@@ -533,13 +535,14 @@ test('should start the server listening on 0.0.0.0 when running in docker', asyn
533535
t.pass('server closed')
534536
})
535537

536-
// TODO remove skip
537-
test('should start the server with watch options that the child process restart when directory changed', { skip: true }, async (t) => {
538-
t.plan(4)
538+
test('should start the server with watch options that the child process restart when directory changed', { skip: process.platform === 'win32' }, async (t) => {
539+
t.plan(3)
539540
const tmpjs = path.resolve(baseFilename + '.js')
540541

542+
const port = getPort()
543+
541544
await writeFile(tmpjs, 'hello world')
542-
const argv = ['-p', '4042', '-w', './examples/plugin.js']
545+
const argv = ['-p', port, '-w', './examples/plugin.js']
543546
const fastifyEmitter = await start.start(argv)
544547

545548
t.teardown(async () => {
@@ -549,9 +552,6 @@ test('should start the server with watch options that the child process restart
549552
await fastifyEmitter.stop()
550553
})
551554

552-
await once(fastifyEmitter, 'start')
553-
t.pass('should receive start event')
554-
555555
await once(fastifyEmitter, 'ready')
556556
t.pass('should receive ready event')
557557

@@ -563,9 +563,8 @@ test('should start the server with watch options that the child process restart
563563
t.pass('should receive restart event')
564564
})
565565

566-
// TODO remove skip
567-
test('should start the server with watch and verbose-watch options that the child process restart when directory changed with console message about changes ', { skip: true }, async (t) => {
568-
t.plan(5)
566+
test('should start the server with watch and verbose-watch options that the child process restart when directory changed with console message about changes ', { skip: process.platform === 'win32' }, async (t) => {
567+
t.plan(4)
569568

570569
const spy = sinon.spy()
571570
const watch = proxyquire('../lib/watch', {
@@ -580,8 +579,10 @@ test('should start the server with watch and verbose-watch options that the chil
580579

581580
const tmpjs = path.resolve(baseFilename + '.js')
582581

582+
const port = getPort()
583+
583584
await writeFile(tmpjs, 'hello world')
584-
const argv = ['-p', '4042', '-w', '--verbose-watch', './examples/plugin.js']
585+
const argv = ['-p', port, '-w', '--verbose-watch', './examples/plugin.js']
585586
const fastifyEmitter = await start.start(argv)
586587

587588
t.teardown(async () => {
@@ -591,9 +592,6 @@ test('should start the server with watch and verbose-watch options that the chil
591592
await fastifyEmitter.stop()
592593
})
593594

594-
await once(fastifyEmitter, 'start')
595-
t.pass('should receive start event')
596-
597595
await once(fastifyEmitter, 'ready')
598596
t.pass('should receive ready event')
599597

@@ -603,11 +601,10 @@ test('should start the server with watch and verbose-watch options that the chil
603601
// this might happen more than once but does not matter in this context
604602
await once(fastifyEmitter, 'restart')
605603
t.pass('should receive restart event')
606-
607-
t.ok(spy.calledOnce, 'should print a console message on file update')
604+
t.ok(spy.args.length > 0, 'should print a console message on file update')
608605
})
609606

610-
test('should reload the env on restart when watching', { skip: true }, async (t) => {
607+
test('should reload the env on restart when watching', { skip: process.platform === 'win32' }, async (t) => {
611608
const testdir = t.testdir({
612609
'.env': 'GREETING=world',
613610
'plugin.js': await readFile(path.join(__dirname, '../examples/plugin-with-env.js'))

0 commit comments

Comments
 (0)