@uscreen.de/create-fastify-app 1.1.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintcache CHANGED
@@ -1 +1 @@
1
- [{"/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js":"1","/Users/martin/repos/uscreen/npm/create-fastify-app/test/cli.test.js":"2","/Users/martin/repos/uscreen/npm/create-fastify-app/test/setup.js":"3"},{"size":3522,"mtime":1675168988666,"results":"4","hashOfConfig":"5"},{"size":2397,"mtime":1675169193473,"results":"6","hashOfConfig":"5"},{"size":717,"mtime":1675081403094,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","suppressedMessages":"10","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1ohqtje",{"filePath":"11","messages":"12","suppressedMessages":"13","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"14","messages":"15","suppressedMessages":"16","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js",[],[],"/Users/martin/repos/uscreen/npm/create-fastify-app/test/cli.test.js",[],[],"/Users/martin/repos/uscreen/npm/create-fastify-app/test/setup.js",[],[]]
1
+ [{"/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js":"1"},{"size":3451,"mtime":1744123221597,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","suppressedMessages":"6","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1cjo6f4","/Users/martin/repos/uscreen/npm/create-fastify-app/bin/cli.js",[],[]]
@@ -14,22 +14,28 @@ jobs:
14
14
  runs-on: ubuntu-latest
15
15
  strategy:
16
16
  matrix:
17
- node-version: [18, 20]
17
+ node-version: [18, 20, 22]
18
18
  steps:
19
19
  - name: Checkout code
20
- uses: actions/checkout@v3
20
+ uses: actions/checkout@v4
21
+
22
+ - name: Install pnpm
23
+ uses: pnpm/action-setup@v4
24
+ with:
25
+ version: 9
26
+ run_install: false
21
27
 
22
28
  - name: Use Node.js ${{ matrix.node-version }}
23
- uses: actions/setup-node@v3
29
+ uses: actions/setup-node@v4
24
30
  with:
25
31
  node-version: ${{ matrix.node-version }}
26
- cache: "npm"
32
+ cache: "pnpm"
27
33
 
28
34
  - name: Install packages
29
- run: npm install
35
+ run: pnpm install
30
36
 
31
37
  - name: Run tests
32
- run: npm run test:ci
38
+ run: pnpm run test:ci
33
39
 
34
40
  - name: Coveralls
35
41
  uses: coverallsapp/github-action@master
package/.gitignore CHANGED
@@ -1,8 +1,7 @@
1
1
  /node_modules
2
2
  .DS_Store
3
- yarn-error.log
4
3
  /.nyc_output
5
4
  /coverage
6
- /skeleton/yarn.lock
5
+ /skeleton/pnpm-lock.yaml
7
6
  /test/_arena
8
7
  /.eslintcache
package/.yarnrc ADDED
@@ -0,0 +1,2 @@
1
+ version-tag-prefix ""
2
+ version-commit-hooks false
package/README.md CHANGED
@@ -7,30 +7,29 @@
7
7
 
8
8
  > cli to quickly bootstrap a new fastify-app
9
9
 
10
- This package provides the cli skript to create a new `@uscreen.de/fastify-app` from scratch. No need to install any other prerequisites than node and yarn. Features include:
10
+ This package provides the cli skript to create a new `@uscreen.de/fastify-app` from scratch inside of a monorepo. No need to install any other prerequisites than node and pnpm. Features include:
11
11
 
12
- * initialize new __git__ repository
13
- * initialize new __yarn__ package.json
14
- * install all __dependencies__ and __devDependencies__
15
- * add __skripts__ and __hooks__ to package.json
12
+ * initialize new package.json
16
13
  * setup __application skeleton__
17
- * setup __dotfiles__ and __linting__
14
+ * setup __dotfiles__
18
15
  * setup __.env__ for starting
19
16
 
20
17
  ## Usage
21
18
 
22
- Use `yarn create` to create a new fastify-app, like so:
19
+ Use `pnpm create` to create a new fastify-app, like so:
23
20
 
24
21
  ```bash
25
- $ yarn create @uscreen.de/fastify-app new-app
22
+ $ pnpm create @uscreen.de/fastify-app new-app
26
23
  ```
27
24
 
28
- and follow instructions. It will create a directory called `new-app` inside the current folder.
29
- Inside that directory, it will generate the initial project structure and install any dependencies:
25
+ It will create a directory called `new-app` inside the current folder.
26
+ Inside that directory, it will generate the initial project structure:
30
27
 
31
28
  ```bash
32
29
  new-app
33
- ├── Makefile
30
+ ├── .env
31
+ ├── .env.example
32
+ ├── .gitignore
34
33
  ├── README.md
35
34
  ├── app
36
35
  │   ├── app.js
@@ -42,15 +41,13 @@ new-app
42
41
  │   └── services
43
42
  │   └── noop.js
44
43
  ├── package.json
45
- ├── pm2-dev.config.cjs
46
- ├── pm2.config.cjs
47
- ├── test
48
- │   ├── helper.js
49
- │   └── noop.test.js
50
- └── yarn.lock
44
+ └── test
45
+     ├── app
46
+     │   └── noop.test.js
47
+     └── helper.js
51
48
  ```
52
49
 
53
- `yarn create` will update itself and checkout the latest version of the boilerplate packed with lot's of best-practice settings and prepared for local dev and pm2 deployment.
50
+ `pnpm create` will update itself and checkout the latest version of the boilerplate packed with lot's of best-practice settings and prepared for local dev.
54
51
 
55
52
  More Details can be found in `@uscreen.de/fastify-app` [README](https://www.npmjs.com/package/@uscreen.de/fastify-app)
56
53
 
@@ -58,8 +55,8 @@ After creation has finished cd into the new apps directory and check it's README
58
55
 
59
56
  ```bash
60
57
  $ cd ./new-app
61
- $ make start
62
- $ make logs
58
+ $ pnpm install
59
+ $ pnpm dev
63
60
  ```
64
61
 
65
62
  ---
@@ -73,6 +70,18 @@ $ make logs
73
70
 
74
71
  ## Changelog
75
72
 
73
+ ### 2.0.0
74
+
75
+ #### Changed
76
+
77
+ - changed skeleton & creation process so it's suitable for use in a monorepo
78
+ - upgraded skeleton to fastify@5
79
+ - use pnpm instead of yarn
80
+
81
+ #### Removed
82
+
83
+ - `-y` option (it is default now)
84
+
76
85
  ### 1.1.2
77
86
 
78
87
  #### Changed
package/bin/cli.js CHANGED
@@ -20,57 +20,26 @@ let root
20
20
  let skeleton
21
21
 
22
22
  /**
23
- * init new git
23
+ * ensure path of new app
24
24
  */
25
- const initializeGitRepository = (path) =>
26
- new Promise((resolve, reject) => {
27
- const git = spawn('git', ['init', path])
28
- git.stdout.on('data', (data) => process.stdout.write(data))
29
- git.stderr.on('data', (data) => process.stderr.write(data))
30
- git.on('close', (code) => {
31
- if (code === 0) return resolve(code)
32
- /* c8 ignore next */
33
- reject(code)
34
- })
35
- })
25
+ const ensurePath = (path) => fs.ensureDir(path)
36
26
 
37
27
  /**
38
- * init new yarn project
28
+ * init new pnpm project
39
29
  */
40
- const initializeYarn = (path, { yes } = {}) =>
30
+ const initializePnpm = (path) =>
41
31
  new Promise((resolve, reject) => {
42
- const params = ['init']
43
- if (yes) params.push('-y')
44
-
45
- const yarn = spawn('yarn', params, {
32
+ const pnpm = spawn('pnpm', ['init'], {
46
33
  cwd: path,
47
34
  stdio: [0, 1, 2]
48
35
  })
49
- yarn.on('close', (code) => {
36
+ pnpm.on('close', (code) => {
50
37
  if (code === 0) return resolve(code)
51
38
  /* c8 ignore next */
52
39
  reject(code)
53
40
  })
54
41
  })
55
42
 
56
- /**
57
- * install packages
58
- */
59
- const installPackages = (appPath) => {
60
- return new Promise((resolve, reject) => {
61
- const yarn = spawn('yarn', ['install'], {
62
- cwd: appPath
63
- })
64
- yarn.stdout.on('data', (data) => process.stdout.write(data))
65
- yarn.stderr.on('data', (data) => process.stderr.write(data))
66
- yarn.on('close', (code) => {
67
- if (code === 0) return resolve(code)
68
- /* c8 ignore next */
69
- reject(code)
70
- })
71
- })
72
- }
73
-
74
43
  /**
75
44
  * configure package.json to use linting, testing, stuff
76
45
  */
@@ -83,7 +52,6 @@ const addPackageConfig = (path, skelPath) => {
83
52
  pack.packageJson.main = skelPack.packageJson.main
84
53
  pack.packageJson.type = skelPack.packageJson.type
85
54
  pack.packageJson.scripts = skelPack.packageJson.scripts
86
- pack.packageJson['lint-staged'] = skelPack.packageJson['lint-staged']
87
55
 
88
56
  pack.packageJson.dependencies = skelPack.packageJson.dependencies
89
57
  pack.packageJson.devDependencies = skelPack.packageJson.devDependencies
@@ -117,8 +85,7 @@ const copyEnv = (appPath, skelPath) => {
117
85
  program
118
86
  .version(version)
119
87
  .arguments('<name>')
120
- .option('-y --yes')
121
- .action(async (name, opt) => {
88
+ .action(async (name) => {
122
89
  /**
123
90
  * the root directory of new project
124
91
  */
@@ -132,10 +99,9 @@ program
132
99
  /**
133
100
  * setup new app
134
101
  */
135
- await initializeGitRepository(root)
136
- await initializeYarn(root, opt)
102
+ await ensurePath(root)
103
+ await initializePnpm(root)
137
104
  await addPackageConfig(root, skeleton)
138
- await installPackages(root)
139
105
  await copySkeleton(root, skeleton)
140
106
  await copyEnv(root, skeleton)
141
107
  })
package/manifest.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": "2.0.1"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uscreen.de/create-fastify-app",
3
- "version": "1.1.3",
3
+ "version": "2.0.1",
4
4
  "description": "cli to create a new @uscreen.de/fastify-app",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -14,28 +14,21 @@
14
14
  "bin": {
15
15
  "create-fastify-app": "./bin/cli.js"
16
16
  },
17
- "scripts": {
18
- "test": "c8 tap",
19
- "test:cov": "c8 --reporter=html --reporter=text tap",
20
- "test:ci": "c8 --reporter=lcovonly tap",
21
- "lint": "eslint --fix",
22
- "prepare": "husky install"
23
- },
24
17
  "dependencies": {
25
- "commander": "^11.0.0",
26
- "fs-extra": "^11.1.0",
27
- "read-pkg-up": "^10.0.0",
28
- "write-pkg": "^6.0.0"
18
+ "commander": "^14.0.1",
19
+ "fs-extra": "^11.3.2",
20
+ "read-pkg-up": "^11.0.0",
21
+ "write-pkg": "^7.0.0"
29
22
  },
30
23
  "devDependencies": {
31
- "@uscreen.de/eslint-config-prettystandard-node": "^0.2.10",
32
- "c8": "^8.0.0",
33
- "husky": ">=8.0.2",
34
- "lint-staged": ">=13.0.3",
35
- "strip-ansi": "^7.0.1",
36
- "tap": "^16.3.4"
24
+ "@uscreen.de/eslint-config-prettystandard-node": "^0.2.12",
25
+ "c8": "^10.1.3",
26
+ "strip-ansi": "^7.1.2"
37
27
  },
38
- "lint-staged": {
39
- "*.js": "eslint --cache --fix"
28
+ "scripts": {
29
+ "lint": "eslint --fix",
30
+ "test": "node --test --test-reporter spec ./test",
31
+ "test:cov": "c8 --reporter=html --reporter=text node --test ./test",
32
+ "test:ci": "find ./test -name '*.test.js' | xargs c8 --reporter=lcov --reporter=text -- node --test"
40
33
  }
41
- }
34
+ }
@@ -3,5 +3,4 @@ node_modules
3
3
  /.nyc_output
4
4
  /coverage
5
5
  .DS_Store
6
- yarn-error.log
7
6
  /.eslintcache
@@ -1,19 +1,19 @@
1
1
  # ${app-name}
2
2
 
3
- > __TODO:__
3
+ > **TODO:**
4
4
  > add a name & short description of this apps purpose
5
5
 
6
6
  ## Usage
7
7
 
8
- * `make start`: start app on local dev
9
- * `make test`: test app
8
+ - `pnpm run dev`: start app on local dev
9
+ - `pnpm run test`: test app
10
10
 
11
11
  ## Configure
12
12
 
13
- Configuration is read by dotenv from `app/.env` file and validated _[optional modified]_ by `app/config.js`. Please add extra defaults if needed to `config.js`. Default values should __always__ refer to local dev setups.
13
+ Configuration is read by dotenv from `app/.env` file and validated _[optional modified]_ by `app/config.js`. Please add extra defaults if needed to `config.js`. Default values should **always** refer to local dev setups.
14
14
 
15
- > __Note:__
16
- > the `.env` file should __never__ get pushed to repository. So adding secrets and credentials to `.env` can be considered a secure option bound to specific environments.
15
+ > **Note:**
16
+ > the `.env` file should **never** get pushed to repository. So adding secrets and credentials to `.env` can be considered a secure option bound to specific environments.
17
17
 
18
18
  ## Api
19
19
 
@@ -29,7 +29,7 @@ After starting your server you will find swagger documenation at [http://127.0.0
29
29
 
30
30
  ### v0.0.0
31
31
 
32
- - initially bootstrapped by `yarn create @uscreen.de/fastify-app`
32
+ - initially bootstrapped by `pnpm create @uscreen.de/fastify-app`
33
33
 
34
34
  ---
35
35
 
@@ -2,16 +2,16 @@ import fastifyApp from '@uscreen.de/fastify-app'
2
2
  import fp from 'fastify-plugin'
3
3
  import schemas from './schemas.js'
4
4
 
5
- export default fp((fastify, opts, next) => {
5
+ export default fp((app, opts, next) => {
6
6
  /**
7
7
  * add schemas
8
8
  */
9
- fastify.register(schemas)
9
+ app.register(schemas)
10
10
 
11
11
  /**
12
12
  * register app
13
13
  */
14
- fastify.register(fastifyApp, opts)
14
+ app.register(fastifyApp, opts)
15
15
 
16
16
  next()
17
17
  })
@@ -1,5 +1,5 @@
1
- import envSchema from 'env-schema'
2
1
  import CommonESM from '@uscreen.de/common-esm'
2
+ import envSchema from 'env-schema'
3
3
 
4
4
  const { join } = new CommonESM(import.meta.url)
5
5
 
@@ -15,7 +15,7 @@ const schema = {
15
15
  }
16
16
 
17
17
  const config = envSchema({
18
- schema: schema,
18
+ schema,
19
19
  dotenv: true
20
20
  })
21
21
 
@@ -1,8 +1,8 @@
1
1
  import fp from 'fastify-plugin'
2
2
 
3
3
  export default fp(
4
- (fastify, opts, next) => {
5
- fastify.decorate('noop', () => {
4
+ (app, opts, next) => {
5
+ app.decorate('noop', () => {
6
6
  return 'Hello Universe'
7
7
  })
8
8
 
@@ -5,9 +5,9 @@ import S from 'fluent-json-schema'
5
5
  * Usage of the Globaly Shared Schema feature
6
6
  */
7
7
 
8
- export default fp((fastify, opts, next) => {
8
+ export default fp((app, opts, next) => {
9
9
  const addSchema = (schema) => {
10
- fastify.addSchema(schema)
10
+ app.addSchema(schema)
11
11
  return schema
12
12
  }
13
13
 
@@ -1,8 +1,10 @@
1
- import fastify from 'fastify'
1
+ import process from 'node:process'
2
2
  import { options } from '@uscreen.de/fastify-app'
3
- import config from './config.js'
3
+ import fastify from 'fastify'
4
4
  import app from './app.js'
5
5
 
6
+ import config from './config.js'
7
+
6
8
  const server = fastify(options(config))
7
9
 
8
10
  server.register(app, config)
@@ -11,10 +13,12 @@ server.register(app, config)
11
13
  * post-treatment
12
14
  */
13
15
  server.ready((err) => {
14
- if (err) throw err
16
+ if (err) {
17
+ throw err
18
+ }
15
19
  server.log.debug(
16
- 'server ready, routes are set:\n' +
17
- server.printRoutes({ commonPrefix: false })
20
+ `server ready, routes are set:\n${
21
+ server.printRoutes({ commonPrefix: false })}`
18
22
  )
19
23
  })
20
24
 
@@ -1,18 +1,18 @@
1
- export default (fastify, opts, next) => {
2
- fastify.get(
1
+ export default (app, opts, next) => {
2
+ app.get(
3
3
  '/noop',
4
4
  {
5
5
  schema: {
6
6
  response: {
7
- 200: { $ref: 'noopNplugin#' } // fastest and json-schema spec compatiple way, or use 'fastify.getSchema()'
8
- // 200: fastify.getSchema('noopNplugin')
7
+ 200: { $ref: 'noopNplugin#' } // fastest and json-schema spec compatiple way, or use 'app.getSchema()'
8
+ // 200: app.getSchema('noopNplugin')
9
9
  }
10
10
  }
11
11
  },
12
- async (req, res) => {
12
+ async (/* req, res */) => {
13
13
  return {
14
14
  noop: 'Hello world',
15
- plugin: fastify.noop(),
15
+ plugin: app.noop(),
16
16
  property: 'should be stripped from response'
17
17
  }
18
18
  }
@@ -1,35 +1,25 @@
1
1
  {
2
2
  "name": "new-fastify-app",
3
+ "type": "module",
3
4
  "version": "0.0.0",
4
5
  "main": "app/server.js",
5
- "type": "module",
6
+ "scripts": {
7
+ "dev": "nodemon",
8
+ "test": "node --test --test-reporter spec",
9
+ "test:cov": "c8 --reporter=html --reporter=text node --test",
10
+ "test:ci": "node --test"
11
+ },
6
12
  "dependencies": {
13
+ "@fastify/one-line-logger": "^2.0.0",
7
14
  "@uscreen.de/common-esm": "^1.0.0",
8
- "@uscreen.de/fastify-app": "^1.0.0-0",
9
- "env-schema": "^5.1.1",
10
- "fastify": "^4.10.2",
11
- "fastify-plugin": "^4.3.0",
12
- "fluent-json-schema": "^4.0.0",
13
- "pino-pretty": "^9.1.1"
15
+ "@uscreen.de/fastify-app": "^3.0.0",
16
+ "env-schema": "^6.0.0",
17
+ "fastify": "^5.0.0",
18
+ "fastify-plugin": "^5.0.0",
19
+ "fluent-json-schema": "^5.0.0"
14
20
  },
15
21
  "devDependencies": {
16
- "@uscreen.de/eslint-config-prettystandard-node": "^0.2.8",
17
- "c8": "^7.12.0",
18
- "husky": ">=6",
19
- "lint-staged": ">=10",
20
- "nodemon": "^2.0.20",
21
- "prettier": "^2.8.0",
22
- "tap": "^16.3.2"
23
- },
24
- "scripts": {
25
- "dev": "nodemon",
26
- "lint": "eslint --fix",
27
- "test": "c8 tap",
28
- "test:cov": "c8 --reporter=html --reporter=text tap",
29
- "test:ci": "tap",
30
- "prepare": "husky install"
31
- },
32
- "lint-staged": {
33
- "*.js": "eslint --cache --fix"
22
+ "c8": "^10.0.0",
23
+ "nodemon": "^3.0.0"
34
24
  }
35
25
  }
@@ -1,45 +1,50 @@
1
- import tap from 'tap'
1
+ import assert from 'node:assert/strict'
2
+ import test from 'node:test'
2
3
  import { build } from '../helper.js'
3
4
 
4
- tap.test('Test Setup', (t) => {
5
- t.equal(true, true, 'Tests and assertions should work')
6
- t.end()
5
+ test('Test Setup', (t, done) => {
6
+ assert.equal(true, true, 'Tests and assertions should work')
7
+ done()
7
8
  })
8
9
 
9
- tap.test('Healthcheck', async (t) => {
10
- const fastify = await build(t)
11
- const { prefix } = fastify.config
10
+ test('Healthcheck', async (t) => {
11
+ const app = await build(t)
12
+ const { prefix } = app.config
12
13
 
13
- t.test('a valid GET Request', (t) => {
14
- fastify.inject(
14
+ t.test('a valid GET Request', (t, done) => {
15
+ app.inject(
15
16
  {
16
17
  method: 'GET',
17
18
  url: `${prefix}/health`
18
19
  },
19
20
  (e, response) => {
20
- t.error(e)
21
- t.same(response.statusCode, 200, 'response ok')
22
- t.same(JSON.parse(response.body), { status: 'ok' }, 'payload ok')
23
- t.end()
21
+ assert.ok(!e)
22
+ assert.equal(response.statusCode, 200, 'response ok')
23
+ assert.deepEqual(
24
+ JSON.parse(response.body),
25
+ { status: 'ok' },
26
+ 'payload ok'
27
+ )
28
+ done()
24
29
  }
25
30
  )
26
31
  })
27
32
  })
28
33
 
29
- tap.test('Noop Service', async (t) => {
30
- const fastify = await build(t)
31
- const { prefix } = fastify.config
34
+ test('Noop Service', async (t) => {
35
+ const app = await build(t)
36
+ const { prefix } = app.config
32
37
 
33
- t.test('a valid GET Request', (t) => {
34
- fastify.inject(
38
+ t.test('a valid GET Request', (t, done) => {
39
+ app.inject(
35
40
  {
36
41
  method: 'GET',
37
42
  url: `${prefix}/noop`
38
43
  },
39
44
  (e, response) => {
40
- t.error(e)
41
- t.same(response.statusCode, 200, 'response ok')
42
- t.same(
45
+ assert.ok(!e)
46
+ assert.equal(response.statusCode, 200, 'response ok')
47
+ assert.deepEqual(
43
48
  JSON.parse(response.body),
44
49
  {
45
50
  noop: 'Hello world',
@@ -47,7 +52,7 @@ tap.test('Noop Service', async (t) => {
47
52
  },
48
53
  'payload ok'
49
54
  )
50
- t.end()
55
+ done()
51
56
  }
52
57
  )
53
58
  })
@@ -17,13 +17,17 @@ export const build = async (t, ConfigOverwrite = {}) => {
17
17
  app.register(fp(App), { ...Config, ...ConfigOverwrite })
18
18
 
19
19
  // tear down our app after we are done
20
- t.teardown(app.close.bind(app))
20
+ t.after(async () => {
21
+ await app.close()
22
+ })
21
23
 
22
24
  app.ready((err) => {
23
- if (err) throw err
25
+ if (err) {
26
+ throw err
27
+ }
24
28
  resolve(app)
25
29
  })
26
30
  })
27
31
  }
28
32
 
29
- export const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
33
+ export const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
package/test/cli.test.js CHANGED
@@ -1,109 +1,82 @@
1
- import tap from 'tap'
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
2
3
  import fs from 'fs-extra'
3
4
  import path from 'path'
4
5
  import { createRequire } from 'module'
5
6
  import stripAnsi from 'strip-ansi'
6
- import { before, teardown, cli, cwd } from './setup.js'
7
+ import { before, after, cli, cwd } from './setup.js'
7
8
 
8
9
  const require = createRequire(import.meta.url)
9
10
  const { version } = require('../package.json')
10
11
 
11
- tap.before(before)
12
- tap.teardown(teardown)
12
+ test.before(before)
13
+ test.after(after)
13
14
 
14
- tap.test('$ cli', async (t) => {
15
+ test('`$ cli` should print error message', async (t) => {
15
16
  const result = await cli([])
16
- t.equal(
17
+ assert.equal(
17
18
  true,
18
19
  result.stderr.startsWith("error: missing required argument 'name'"),
19
20
  'Should print error message'
20
21
  )
21
-
22
- t.end()
23
22
  })
24
23
 
25
- tap.test('$ cli -V', async (t) => {
24
+ test('`$ cli -V` should show correct version', async (t) => {
26
25
  const result = await cli(['--version'])
27
- t.equal(
28
- true,
29
- result.stdout.startsWith(version),
30
- 'Should show correct version'
31
- )
32
-
33
- t.end()
26
+ assert.equal(true, result.stdout.startsWith(version))
34
27
  })
35
28
 
36
- tap.test('$ cli new-app -y', async (t) => {
37
- const result = await cli(['new-app', '-y'])
38
-
29
+ test('`$ cli new-app` should succeed', async (t) => {
30
+ const result = await cli(['new-app'])
39
31
  /**
40
32
  * check output
41
33
  */
42
- t.equal(0, result.code, 'Should succeed')
34
+ assert.equal(0, result.code, 'Should succeed')
35
+
36
+ await t.test('Check output', (t, done) => {
37
+ const appPath = path.resolve(cwd, 'new-app')
43
38
 
44
- t.test('Check output', (t) => {
45
- const expectedOut = [
46
- `Initialized empty Git repository in ${path.resolve(
47
- cwd,
48
- 'new-app',
49
- '.git'
50
- )}`,
51
- 'success Saved package.json',
52
- '[1/4] Resolving packages...',
53
- '[2/4] Fetching packages...',
54
- '[3/4] Linking dependencies...',
55
- '[4/4] Building fresh packages...',
56
- 'success Saved lockfile.',
57
- 'husky - Git hooks installed'
58
- ]
39
+ const expectedOut = [`Wrote to ${appPath}/package.json`]
59
40
 
60
41
  const stdout = stripAnsi(result.stdout)
61
42
 
62
43
  for (const e of expectedOut) {
63
- t.equal(true, stdout.includes(e), `"${e.substring(0, 36)}"`)
44
+ assert.equal(true, stdout.includes(e), `"${e.substring(0, 36)}"`)
64
45
  }
65
46
 
66
- t.end()
47
+ done()
67
48
  })
68
49
 
69
50
  /**
70
51
  * check files
71
52
  */
72
- t.test('Check files', (t) => {
53
+ await t.test('Check files', (t, done) => {
73
54
  const appPath = path.resolve(cwd, 'new-app')
74
55
 
75
- t.equal(
76
- true,
56
+ assert.ok(
77
57
  fs.existsSync(path.resolve(appPath, 'package.json')),
78
58
  'package.json was created'
79
59
  )
80
- t.equal(
81
- true,
60
+ assert.ok(
82
61
  fs.existsSync(path.resolve(appPath, 'README.md')),
83
62
  'skeleton was copied'
84
63
  )
85
- t.equal(
86
- true,
87
- fs.existsSync(path.resolve(appPath, 'yarn.lock')),
88
- 'Packages were installed'
89
- )
64
+ assert.ok(fs.existsSync(path.resolve(appPath, '.env')), 'Env was copied')
90
65
 
91
66
  const pack = JSON.parse(
92
67
  fs.readFileSync(path.resolve(appPath, 'package.json'), {
93
68
  encoding: 'utf-8'
94
69
  })
95
70
  )
96
- t.equal(
97
- true,
71
+ assert.ok(
98
72
  pack.name !== 'new-fastify-app',
99
73
  'package.json was not just copied from skeleton'
100
74
  )
101
- t.equal(
102
- true,
75
+ assert.ok(
103
76
  pack.main === 'app/server.js',
104
77
  'package.json was correctly enriched with data'
105
78
  )
106
79
 
107
- t.end()
80
+ done()
108
81
  })
109
82
  })
package/test/setup.js CHANGED
@@ -28,6 +28,6 @@ export const before = () => {
28
28
  fs.ensureDirSync(cwd)
29
29
  }
30
30
 
31
- export const teardown = () => {
31
+ export const after = () => {
32
32
  fs.removeSync(cwd)
33
33
  }
package/.husky/.gitignore DELETED
@@ -1 +0,0 @@
1
- _
@@ -1 +0,0 @@
1
- *
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npx lint-staged
@@ -1,13 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- indent_style = space
6
- indent_size = 2
7
- end_of_line = lf
8
- insert_final_newline = true
9
- trim_trailing_whitespace = true
10
-
11
- [{Makefile,**.mk}]
12
- # Use tabs for indentation (Makefiles require tabs)
13
- indent_style = tab
package/skeleton/.envrc DELETED
@@ -1,4 +0,0 @@
1
- # @see https://direnv.net/ and https://github.com/direnv/direnv/wiki/Node for docs
2
- set -e
3
- use node
4
- layout node
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "@uscreen.de/eslint-config-prettystandard-node"
3
- }
@@ -1,25 +0,0 @@
1
- # image: node:lts-alpine
2
-
3
- # cache:
4
- # paths:
5
- # - node_modules/
6
- # - .yarn
7
-
8
- # stages:
9
- # - test
10
- # - audit
11
-
12
- # test:
13
- # stage: test
14
- # script:
15
- # - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
16
- # - yarn install --pure-lockfile --cache-folder .yarn
17
- # - yarn test:ci
18
- # coverage: '/^Statements\s*:\s*([^%]+)/'
19
-
20
- # audit:
21
- # stage: audit
22
- # only:
23
- # - schedules
24
- # script:
25
- # - yarn audit
package/skeleton/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 20
package/skeleton/.taprc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "timeout": 10,
3
- "reporter": "spec",
4
- "check-coverage": false,
5
- "no-coverage": true,
6
- "test-regex": "\\w+\\.test\\.js$"
7
- }
package/skeleton/Makefile DELETED
@@ -1,11 +0,0 @@
1
- start:
2
- yarn
3
- yarn dev
4
-
5
- test:
6
- yarn test
7
-
8
- test.coverage:
9
- yarn test:cov
10
-
11
- .PHONY: test