Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: webpack test stack #3240

Merged
merged 6 commits into from Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -63,3 +63,23 @@ jobs:
- uses: fastify/github-action-merge-dependabot@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

package:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Use Node.js
uses: actions/setup-node@v2.1.5
with:
node-version: 14
- name: install fastify
run: |
npm install --ignore-scripts
- name: install bundler stack
run: |
cd test/bundler/webpack && npm install
- name: Test bundle
run: |
cd test/bundler/webpack && npm run test

22 changes: 22 additions & 0 deletions test/bundler/webpack/bundler-test.js
@@ -0,0 +1,22 @@
'use strict'

const t = require('tap')
const test = t.test
const fastifySuccess = require('./dist/success')
const fastifyFailPlugin = require('./dist/failPlugin')

test('Bundler should work', t => {
t.plan(1)
fastifySuccess.ready((err) => {
t.error(err)
})
})

// Untill there is no proper solution for bundlers, the fastify version
// is set to undefined for this context
test('Bundler should work with bad plugin version, undefined version', t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test going to pass or not? I'm not sure it would. Maybe we should skip it in case - I want all the CI to stay green.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So theorically on a non bundled environment it would fail, but on bundled environment because of the fallback in here:

return pkg.name === 'fastify' ? pkg.version : undefined
it's set to undefined. So it passes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify the comment so that it's clear what we should change here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

t.plan(1)
fastifyFailPlugin.ready((err) => {
t.error(err)
})
})
11 changes: 11 additions & 0 deletions test/bundler/webpack/package.json
@@ -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"
}
}
14 changes: 14 additions & 0 deletions test/bundler/webpack/src/fail-plugin-version.js
@@ -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
9 changes: 9 additions & 0 deletions test/bundler/webpack/src/index.js
@@ -0,0 +1,9 @@
const fastify = require('../../../../')({
logger: true
})
// Declare a route
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})

module.exports = fastify
13 changes: 13 additions & 0 deletions test/bundler/webpack/webpack.config.js
@@ -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'
}
}
}