Skip to content

Commit

Permalink
test: adding esbuild bundler to CI pipeline (#3616)
Browse files Browse the repository at this point in the history
* test: adding esbuild bundler test

* test: adding esbuild to package ci

* test: updating bundle test

* test: check message labels on bundlers
  • Loading branch information
jhonrocha committed Jan 13, 2022
1 parent 670e7d6 commit 93fe532
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 12 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
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
@@ -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) => {
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.match(err.message, /expected '9.x' fastify version/i)
})
})
10 changes: 10 additions & 0 deletions test/bundler/esbuild/package.json
@@ -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
@@ -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
@@ -0,0 +1,7 @@
const fastify = require('../../../../')()
// Declare a route
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})

module.exports = fastify
19 changes: 15 additions & 4 deletions test/bundler/webpack/bundler-test.js
Expand Up @@ -5,16 +5,27 @@ 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)
t.match(err.message, /expected '9.x' fastify version/i)
})
})
4 changes: 1 addition & 3 deletions test/bundler/webpack/src/fail-plugin-version.js
@@ -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
@@ -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

0 comments on commit 93fe532

Please sign in to comment.