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

Adding esbuild bundler to the pipeline #3616

Merged
merged 4 commits into from
Jan 13, 2022
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
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ jobs:
- name: install fastify
run: |
npm install --ignore-scripts
- name: install bundler stack
- name: install webpack stack
run: |
cd test/bundler/webpack && npm install
- name: Test bundle
- name: Test webpack bundle
run: |
cd test/bundler/webpack && npm run test
- name: install esbuild stack
run: |
cd test/bundler/esbuild && npm install
- name: Test esbuild bundle
run: |
cd test/bundler/esbuild && npm run test
31 changes: 31 additions & 0 deletions test/bundler/esbuild/bundler-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'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(4)
fastifySuccess.ready((err) => {
Copy link
Member

Choose a reason for hiding this comment

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

Use the inject to test if the route was registered with success

t.error(err)
fastifySuccess.inject(
{
method: 'GET',
url: '/'
},
(error, res) => {
t.error(error)
t.equal(res.statusCode, 200)
t.same(res.json(), { hello: 'world' })
}
)
})
})

test('Bundled package should not work with bad plugin version', (t) => {
t.plan(1)
fastifyFailPlugin.ready((err) => {
t.ok(err)
Eomm marked this conversation as resolved.
Show resolved Hide resolved
})
})
10 changes: 10 additions & 0 deletions test/bundler/esbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "0.0.1",
"scripts": {
"bundle": "esbuild success=src/index.js failPlugin=src/fail-plugin-version.js --bundle --outdir=dist --platform=node",
"test": "npm run bundle && node bundler-test.js"
},
"devDependencies": {
"esbuild": "^0.14.11"
}
}
12 changes: 12 additions & 0 deletions test/bundler/esbuild/src/fail-plugin-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fp = require('fastify-plugin')
const fastify = require('../../../../')()

fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})

fastify.register(fp((instance, opts, done) => {
done()
}, { fastify: '9.x' }))

module.exports = fastify
7 changes: 7 additions & 0 deletions test/bundler/esbuild/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fastify = require('../../../../')()
// Declare a route
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})

module.exports = fastify
17 changes: 14 additions & 3 deletions test/bundler/webpack/bundler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ const test = t.test
const fastifySuccess = require('./dist/success')
const fastifyFailPlugin = require('./dist/failPlugin')

test('Bundled package should work', t => {
t.plan(1)
test('Bundled package should work', (t) => {
t.plan(4)
fastifySuccess.ready((err) => {
t.error(err)
fastifySuccess.inject(
{
method: 'GET',
url: '/'
},
(error, res) => {
t.error(error)
t.equal(res.statusCode, 200)
t.same(res.json(), { hello: 'world' })
}
)
})
})

test('Bundled package should not work with bad plugin version', t => {
test('Bundled package should not work with bad plugin version', (t) => {
t.plan(1)
fastifyFailPlugin.ready((err) => {
t.ok(err)
Expand Down
4 changes: 1 addition & 3 deletions test/bundler/webpack/src/fail-plugin-version.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const fp = require('fastify-plugin')
const fastify = require('../../../../')({
logger: true
})
const fastify = require('../../../../')()

fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
Expand Down
4 changes: 1 addition & 3 deletions test/bundler/webpack/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const fastify = require('../../../../')({
logger: true
})
const fastify = require('../../../../')()
// Declare a route
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
Expand Down