Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add webpack test stack * feat: add bundler test version * fix: set minimum version * docs: add bundler test doc * fix: review Co-authored-by: Matteo Collina <hello@matteocollina.com>
- Loading branch information
Showing
7 changed files
with
119 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Bundlers test stack | ||
|
||
In some cases developers bundle their apps for several targets, eg: serveless applications. | ||
Even if it's not recommended by Fastify team; we need to ensure we do not break the build process. | ||
Please note this might result in feature behaving differently like the version handling check for plugins. | ||
|
||
## Test bundlers | ||
|
||
The bundler test stack has been set appart than the rest of the Unit testing stack because it's not a | ||
part of the fastify lib itself. Note that the tests run in CI only on NodeJs LTS version. | ||
Developers does not need to install every bundler to run unit tests. | ||
|
||
To run the bundler tests you'll need to first install the repository dependencies and after the bundler | ||
stack dependencies. See: | ||
|
||
```bash | ||
# path: root of repository /fastify | ||
npm i | ||
cd test/bundler/webpack | ||
npm i | ||
npm run test # test command runs bundle before of starting the test | ||
``` | ||
|
||
## Bundler test development | ||
|
||
To not break the fastify unit testing stack please name test files like this `*-test.js` and not `*.test.js`, | ||
otherwise it can be catched by unit-test regex of fastify. | ||
Test need to ensure the build process works and the fastify application can be run, | ||
no need to go in deep testing unless an issue is raised. |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const test = t.test | ||
const fastifySuccess = require('./dist/success') | ||
const fastifyFailPlugin = require('./dist/failPlugin') | ||
|
||
test('Bundled package should work', t => { | ||
t.plan(1) | ||
fastifySuccess.ready((err) => { | ||
t.error(err) | ||
}) | ||
}) | ||
|
||
// In the webpack bundle context the fastify package.json is not read | ||
// Because of this the version is set to `undefined`, this makes the plugin | ||
// version check not able to work properly. By then this test shouldn't work | ||
// in non-bundled environment but works in bundled environment | ||
test('Bundled package should work with bad plugin version, undefined version fallback', t => { | ||
t.plan(1) | ||
fastifyFailPlugin.ready((err) => { | ||
t.error(err) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version":"0.0.1", | ||
"scripts": { | ||
"bundle": "webpack", | ||
"test": "npm run bundle && node bundler-test.js" | ||
}, | ||
"devDependencies": { | ||
"webpack": "^5.49.0", | ||
"webpack-cli": "^4.7.2" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const fp = require('fastify-plugin') | ||
const fastify = require('../../../../')({ | ||
logger: true | ||
}) | ||
|
||
fastify.get('/', function (request, reply) { | ||
reply.send({ hello: 'world' }) | ||
}) | ||
|
||
fastify.register(fp((instance, opts, done) => { | ||
done() | ||
}, { fastify: '9.x' })) | ||
|
||
module.exports = fastify |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const fastify = require('../../../../')({ | ||
logger: true | ||
}) | ||
// Declare a route | ||
fastify.get('/', function (request, reply) { | ||
reply.send({ hello: 'world' }) | ||
}) | ||
|
||
module.exports = fastify |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const path = require('path') | ||
|
||
module.exports = { | ||
entry: { success: './src/index.js', failPlugin: './src/fail-plugin-version.js' }, | ||
target: 'node', | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].js', | ||
library: { | ||
type: 'commonjs2' | ||
} | ||
} | ||
} |