Socket
Socket
Sign inDemoInstall

serverless-jest-plugin

Package Overview
Dependencies
343
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

__tests__/integration-options.test.js

53

__tests__/integration4.3.test.js

@@ -6,4 +6,8 @@ 'use strict';

const path = require('path');
const fse = require('fs-extra');
const testUtils = require('./test-utils');
const fs = require('fs-extra');
const {
getTmpDirPath,
replaceTextInFile,
spawnPromise,
} = require('./test-utils');

@@ -17,20 +21,29 @@ const serverless = new Serverless();

process.env.PLUGIN_TEST_DIR = path.join(__dirname);
const tmpDir = testUtils.getTmpDirPath();
fse.mkdirsSync(tmpDir);
fse.copySync(path.join(process.env.PLUGIN_TEST_DIR, 'test-service4.3'), tmpDir);
fse.copySync(path.join(process.env.PLUGIN_TEST_DIR, '..'), path.join(tmpDir, '.local'));
const tmpDir = getTmpDirPath();
fs.mkdirsSync(tmpDir);
fs.copySync(path.join(process.env.PLUGIN_TEST_DIR, 'test-service4.3'), tmpDir);
fs.copySync(path.join(process.env.PLUGIN_TEST_DIR, '..'), path.join(tmpDir, '.local'));
const packageJsonPath = path.join(tmpDir, 'package.json');
const packageJson = fse.readJsonSync(packageJsonPath);
const packageJson = fs.readJsonSync(packageJsonPath);
packageJson.name = `application-${Date.now()}`;
packageJson.dependencies['serverless-jest-plugin'] = `file:${tmpDir}/.local`;
fse.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
process.chdir(tmpDir);
});
afterAll(() => {
// remove temp dir
fs.removeSync(process.cwd());
});
it('should contain test params in cli info', () => {
const test = execSync(serverlessExec);
const result = new Buffer(test, 'base64').toString();
expect(result).toContain('create test ................... Create jest tests for service / function');
expect(result).toContain('create function ............... Create a function into the service');
expect(result).toContain('invoke test ................... Invoke test(s)');
expect(result).toContain('create test');
expect(result).toContain('Create jest tests for service / function');
expect(result).toContain('create function');
expect(result).toContain('Create a function into the service');
expect(result).toContain('invoke test');
expect(result).toContain('Invoke test(s)');
expect(result).toContain('ServerlessJestPlugin');
});

@@ -41,3 +54,3 @@

const result = new Buffer(test, 'base64').toString();
expect(result).toContain('Serverless: Created test file __tests__/hello.test.js');
expect(result).toContain('Created test file __tests__/hello.test.js');
});

@@ -48,3 +61,3 @@

const result = new Buffer(test, 'base64').toString();
expect(result).toContain('Serverless: Created function file goodbye/index.js');
expect(result).toContain('Created function file goodbye/index.js');
});

@@ -55,14 +68,16 @@

// change test files to use local proxy version of jest plugin
testUtils.replaceTextInFile(
replaceTextInFile(
path.join('__tests__', 'hello.test.js'),
'require(\'serverless-jest-plugin\')',
'require(\'../.serverless_plugins/serverless-jest-plugin/index.js\')');
testUtils.replaceTextInFile(
replaceTextInFile(
path.join('__tests__', 'goodbye.test.js'),
'require(\'serverless-jest-plugin\')',
'require(\'../.serverless_plugins/serverless-jest-plugin/index.js\')');
const test = execSync(`${serverlessExec} invoke test`);
const result = new Buffer(test, 'base64').toString();
expect(result).toContain('');
});
return spawnPromise(serverlessExec, 'invoke test --stage prod')
.then(({ stderr }) => {
expect(stderr).toContain('PASS');
return expect(stderr).toContain('Test Suites: 2 passed, 2 total');
});
}, 120000);
});

@@ -6,4 +6,8 @@ 'use strict';

const path = require('path');
const fse = require('fs-extra');
const testUtils = require('./test-utils');
const fs = require('fs-extra');
const {
getTmpDirPath,
replaceTextInFile,
spawnPromise,
} = require('./test-utils');

@@ -17,20 +21,29 @@ const serverless = new Serverless();

process.env.PLUGIN_TEST_DIR = path.join(__dirname);
const tmpDir = testUtils.getTmpDirPath();
fse.mkdirsSync(tmpDir);
fse.copySync(path.join(process.env.PLUGIN_TEST_DIR, 'test-service6.10'), tmpDir);
fse.copySync(path.join(process.env.PLUGIN_TEST_DIR, '..'), path.join(tmpDir, '.local'));
const tmpDir = getTmpDirPath();
fs.mkdirsSync(tmpDir);
fs.copySync(path.join(process.env.PLUGIN_TEST_DIR, 'test-service6.10'), tmpDir);
fs.copySync(path.join(process.env.PLUGIN_TEST_DIR, '..'), path.join(tmpDir, '.local'));
const packageJsonPath = path.join(tmpDir, 'package.json');
const packageJson = fse.readJsonSync(packageJsonPath);
const packageJson = fs.readJsonSync(packageJsonPath);
packageJson.name = `application-${Date.now()}`;
packageJson.dependencies['serverless-jest-plugin'] = `file:${tmpDir}/.local`;
fse.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
process.chdir(tmpDir);
});
afterAll(() => {
// remove temp dir
fs.removeSync(process.cwd());
});
it('should contain test params in cli info', () => {
const test = execSync(serverlessExec);
const result = new Buffer(test, 'base64').toString();
expect(result).toContain('create test ................... Create jest tests for service / function');
expect(result).toContain('create function ............... Create a function into the service');
expect(result).toContain('invoke test ................... Invoke test(s)');
expect(result).toContain('create test');
expect(result).toContain('Create jest tests for service / function');
expect(result).toContain('create function');
expect(result).toContain('Create a function into the service');
expect(result).toContain('invoke test');
expect(result).toContain('Invoke test(s)');
expect(result).toContain('ServerlessJestPlugin');
});

@@ -41,3 +54,3 @@

const result = new Buffer(test, 'base64').toString();
expect(result).toContain('Serverless: Created test file __tests__/hello.test.js');
expect(result).toContain('Created test file __tests__/hello.test.js');
});

@@ -48,3 +61,3 @@

const result = new Buffer(test, 'base64').toString();
expect(result).toContain('Serverless: Created function file goodbye/index.js');
expect(result).toContain('Created function file goodbye/index.js');
});

@@ -55,14 +68,16 @@

// change test files to use local proxy version of jest plugin
testUtils.replaceTextInFile(
replaceTextInFile(
path.join('__tests__', 'hello.test.js'),
'require(\'serverless-jest-plugin\')',
'require(\'../.serverless_plugins/serverless-jest-plugin/index.js\')');
testUtils.replaceTextInFile(
replaceTextInFile(
path.join('__tests__', 'goodbye.test.js'),
'require(\'serverless-jest-plugin\')',
'require(\'../.serverless_plugins/serverless-jest-plugin/index.js\')');
const test = execSync(`${serverlessExec} invoke test`);
const result = new Buffer(test, 'base64').toString();
expect(result).toContain('');
});
return spawnPromise(serverlessExec, 'invoke test --stage prod')
.then(({ stderr }) => {
expect(stderr).toContain('PASS');
return expect(stderr).toContain('Test Suites: 2 passed, 2 total');
});
}, 120000);
});
'use strict';
const path = require('path');
const fse = require('fs-extra');
const Plugin = require('../index');
describe('plugin', () => {
beforeAll(() => {
const tmp = path.join(__dirname, '../', 'tmp');
fse.mkdirsSync(tmp);
process.chdir(tmp);
});
it('checks that commands exists', () => {

@@ -15,0 +7,0 @@ const plugin = new Plugin({}, {});

{
"name": "application-name",
"name": "application-name-4",
"version": "0.0.1",

@@ -4,0 +4,0 @@ "dependencies": {

{
"name": "application-name",
"name": "application-name-6",
"version": "0.0.1",

@@ -4,0 +4,0 @@ "dependencies": {

@@ -7,2 +7,3 @@ 'use strict';

const path = require('path');
const spawn = require('child_process').spawn;

@@ -19,5 +20,29 @@ const replaceTextInFile = (filePath, subString, newSubString) => {

const spawnPromise = (serverlessExec, params) =>
new Promise((resolve, reject) => {
const test = spawn(serverlessExec, params.split(' '));
let stdout = '';
let stderr = '';
test.stdout.on('data', (data) => {
stdout += data;
});
test.stderr.on('data', (data) => {
stderr += data;
});
test.on('close', (code) => {
if (code > 0) {
return reject(code);
}
return resolve({ stdout, stderr });
});
});
module.exports = {
replaceTextInFile,
getTmpDirPath,
spawnPromise,
};
'use strict';
const path = require('path');
const fse = require('fs-extra');
const fs = require('fs-extra');
const utils = require('../lib/utils.js');

@@ -12,6 +12,11 @@ const testUtils = require('../__tests__/test-utils');

const tmp = testUtils.getTmpDirPath();
fse.mkdirsSync(tmp);
fs.mkdirsSync(tmp);
process.chdir(tmp);
});
afterAll(() => {
// remove temp dir
fs.removeSync(process.cwd());
});
it('tests getTestFilePath for handler', () => {

@@ -40,3 +45,3 @@ const testFilePath = utils.getTestFilePath('handler');

path.join(process.env.PLUGIN_TEST_DIR, '../', 'lib', 'templates', 'test-template.ejs');
const expectedTemplate = fse.readFileSync(templatePath, 'utf-8');
const expectedTemplate = fs.readFileSync(templatePath, 'utf-8');
const template = utils.getTemplateFromFile(templatePath);

@@ -43,0 +48,0 @@ expect(template).toBe(expectedTemplate);

@@ -87,15 +87,12 @@ 'use strict';

this.hooks = {
'create:test:test': () => {
'create:test:test': () =>
BbPromise.bind(this)
.then(() => createTest(this.serverless, this.options));
},
'invoke:test:test': () => {
.then(() => createTest(this.serverless, this.options)),
'invoke:test:test': () =>
BbPromise.bind(this)
.then(() => runTests(this.serverless, this.options));
},
'create:function:create': () => {
.then(() => runTests(this.serverless, this.options)),
'create:function:create': () =>
BbPromise.bind(this)
.then(() => createFunction(this.serverless, this.options))
.then(() => createTest(this.serverless, this.options));
},
.then(() => createTest(this.serverless, this.options)),
};

@@ -102,0 +99,0 @@ }

@@ -5,2 +5,3 @@ 'use strict';

const BbPromise = require('bluebird');
const { setEnv } = require('./utils');

@@ -14,31 +15,23 @@ const runTests = (serverless, options) => new BbPromise((resolve, reject) => {

const stage = options.stage;
const region = options.region;
const vars = new serverless.classes.Variables(serverless);
vars.populateService(options);
allFunctions.forEach(name => setEnv(serverless, name));
serverless.service.load({
stage,
region,
})
.then((inited) => {
Object.assign(serverless, { environment: inited.environment });
const vars = new serverless.classes.Variables(serverless);
vars.populateService(options);
if (functionName) {
if (allFunctions.indexOf(functionName) >= 0) {
setEnv(serverless, functionName);
Object.assign(config, { testRegex: `${functionName}\\.test\\.js$` });
} else {
return reject(`Function "${functionName}" not found`);
}
} else {
const functionsRegex = allFunctions.map(name => `${name}\\.test\\.js$`).join('|');
Object.assign(config, { testRegex: functionsRegex });
}
if (functionName) {
if (allFunctions.indexOf(functionName) >= 0) {
Object.assign(config, { testRegex: `${functionName}\\.test\\.js$` });
} else {
return reject(`Function "${functionName}" not found`);
}
} else {
const functionsRegex = allFunctions.map(name => `${name}\\.test\\.js$`).join('|');
Object.assign(config, { testRegex: functionsRegex });
}
return runCLI({ config },
serverless.config.servicePath,
success => resolve(success));
});
return runCLI({ config },
serverless.config.servicePath,
success => resolve(success));
});
module.exports = runTests;
{
"name": "serverless-jest-plugin",
"version": "0.1.4",
"version": "0.1.5",
"description": "Serverless plugin for test driven development using Jest",

@@ -17,3 +17,3 @@ "main": "index.js",

"aws-sdk": "^2.7.10",
"bluebird": "^3.4.7",
"bluebird": "^3.5.0",
"ejs": "^2.5.5",

@@ -37,4 +37,4 @@ "fs-extra": "^3.0.0",

"eslint-plugin-react": "^6.9.0",
"serverless": "^1.5.1"
"serverless": "^1.13.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc