Skip to content

Commit

Permalink
test: Test "serverless-offline" plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jun 29, 2021
1 parent a80681f commit 2b7154a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/fixtures/programmatic/curated-plugins/_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const path = require('path');
const fsp = require('fs').promises;

const slsDependencyDir = path.resolve(__dirname, 'node_modules/serverless');

// Ensure to remove "serverless" installed as peer-dependency to avoid local fallback
module.exports = async () => fsp.rm(slsDependencyDir, { recursive: true, force: true });
8 changes: 8 additions & 0 deletions test/fixtures/programmatic/curated-plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports.handler = (event, context, callback) => {
callback(null, {
statusCode: 200,
body: JSON.stringify({ message: 'Test', input: event }, null, 2),
});
};
5 changes: 5 additions & 0 deletions test/fixtures/programmatic/curated-plugins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"serverless-offline": "7.0.0"
}
}
23 changes: 23 additions & 0 deletions test/fixtures/programmatic/curated-plugins/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
service: service

configValidationMode: error
frameworkVersion: '*'

provider:
name: aws
runtime: nodejs14.x
lambdaHashingVersion: 20201221

functions:
function:
handler: index.handler
events:
- http:
path: foo
method: GET
- http:
path: foo
method: POST

plugins:
- serverless-offline
38 changes: 38 additions & 0 deletions test/integration/curated-plugins.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const { expect } = require('chai');
const spawn = require('child-process-ext/spawn');
const got = require('got');
const fixturesEngine = require('../fixtures/programmatic');

const serverlessExec = require('../serverlessBinary');

describe('test/integration/curated-plugins.test.js', function () {
this.timeout(1000 * 60 * 10); // Involves time-taking npm install

let serviceDir;
before(async () => {
serviceDir = (await fixturesEngine.setup('curated-plugins')).servicePath;
});

it('should be extended by "serverless-offline"', async () => {
const slsProcessPromise = spawn(serverlessExec, ['offline'], {
cwd: serviceDir,
});
const slsProcess = slsProcessPromise.child;
let output = '';
slsProcess.stdout.on('data', function self(data) {
output += data;
if (output.includes('server ready:')) {
slsProcess.stdout.off('data', self);
got('http://localhost:3000/dev/foo')
.json()
.then(async (responseBody) => {
expect(responseBody.message).to.equal('Test');
})
.finally(() => slsProcess.kill('SIGINT'));
}
});
await slsProcessPromise;
});
});

0 comments on commit 2b7154a

Please sign in to comment.