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

Tests: Upgrade dependencies, improve isolation and experience on Windows #6208

Merged
merged 63 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
8b9815b
Upgrade chai
medikoo Jun 3, 2019
663f74d
Fix equality test
medikoo Jun 3, 2019
2170c2d
Merge branch 'master' into upgrade-chai
medikoo Jun 3, 2019
1eb9deb
Fix instances checking in tests
medikoo Jun 3, 2019
54bdfdf
Update after chai upgrade
medikoo Jun 3, 2019
e75a1ea
Upgrade after chai update
medikoo Jun 3, 2019
9f150b7
Upgrade chai-as-promised to v7
medikoo Jun 3, 2019
304f43f
Update after chai upgrade
medikoo Jun 3, 2019
0cc153b
Upgrade sinon-chai to v3
medikoo Jun 3, 2019
25b20cf
Upgrade mock-require to v3
medikoo Jun 3, 2019
161f4e0
Upgrade proxyquire
medikoo Jun 3, 2019
5854f4c
Ensure needed utils
medikoo Jun 3, 2019
149be17
Add missing utils
medikoo Jun 4, 2019
8a639fe
Increase timeout for randomly failing test
medikoo Jun 4, 2019
35de9c4
Alphabetical order
medikoo Jun 4, 2019
39c7a79
Ensure to expose TMPDIR to nested processes
medikoo Jun 4, 2019
fbe0697
Ensure needed utilities
medikoo Jun 4, 2019
dff3a53
Ensure to print child output in case of failure
medikoo Jun 4, 2019
2dec7d8
Use destructuring
medikoo Jun 4, 2019
91ac186
Ensure needed utils
medikoo Jun 4, 2019
19d4044
Ensure needed utils
medikoo Jun 4, 2019
31f5812
Ensure distinct homedir for each test file run
medikoo Jun 4, 2019
f026cca
Fix lint issue
medikoo Jun 4, 2019
f503671
Fix lint issue
medikoo Jun 4, 2019
8145ad7
Remove temporary homedir after all suites
medikoo Jun 4, 2019
5f2a69d
Merge branch 'master' into upgrade-chai
medikoo Jun 4, 2019
af888c2
Improve comment
medikoo Jun 4, 2019
746fd04
Ensure windows mandatory env vars
medikoo Jun 4, 2019
d9ff5b6
Improve test timeout setting
medikoo Jun 4, 2019
c5c6a92
Skip test on windows when no admin rights
medikoo Jun 4, 2019
6aaac16
Increase test timeout
medikoo Jun 4, 2019
98ce05b
Increase test timeout
medikoo Jun 4, 2019
fd6ca1a
Do not crash if tmp dir delete fails on win
medikoo Jun 4, 2019
f97603c
Turn on colors on Windows
medikoo Jun 4, 2019
3573f8d
Increase test timeout
medikoo Jun 4, 2019
ae8e14c
Fix condition
medikoo Jun 4, 2019
8aba5e3
Ignore failed attempt to remove temporary home dir
medikoo Jun 4, 2019
aa9210e
Increase timeout
medikoo Jun 4, 2019
2086c39
Increase timeout
medikoo Jun 4, 2019
c587e86
Bring back reset of user config
medikoo Jun 4, 2019
0b801a6
Increase timeout
medikoo Jun 4, 2019
25dec54
Use more accurate ensureDirSync
medikoo Jun 4, 2019
9ff21c8
Ensure to handle spawn error
medikoo Jun 4, 2019
7711804
Fix mock
medikoo Jun 4, 2019
dca3174
Patch mocha handling of uncaught exceptions
medikoo Jun 4, 2019
2dd18e9
Link mocha bug report
medikoo Jun 4, 2019
7d23851
Skip tests for not installed runtimes
medikoo Jun 4, 2019
d257303
Improve comment
medikoo Jun 4, 2019
7955e2c
Improve timeout settings
medikoo Jun 4, 2019
7245160
Improve comments
medikoo Jun 4, 2019
c733f82
Increase test timeout setting
medikoo Jun 4, 2019
2bc1b29
Increase timeout
medikoo Jun 4, 2019
194a12e
Skip with notice functionality
medikoo Jun 5, 2019
cde78a9
Skip with notice on lack of admin rights
medikoo Jun 5, 2019
a681503
Support pass of after callback
medikoo Jun 5, 2019
67a67ae
Validate against invalid suite injection
medikoo Jun 5, 2019
aa5658a
Support afterCallback in symlink fail skip
medikoo Jun 5, 2019
0f181ed
Rely on skipWithNotice
medikoo Jun 5, 2019
7502b0d
Shift timeout
medikoo Jun 5, 2019
d3b7d2e
Unify timeout notices
medikoo Jun 5, 2019
036d1b0
Shift timeout setting
medikoo Jun 5, 2019
8ca00b6
Increase default timeout
medikoo Jun 5, 2019
93a632f
Ensure proper context
medikoo Jun 5, 2019
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: "Unit Tests - Windows - Node.js v12"
os: windows
node_js: 12
env:
- SLS_IGNORE_WARNING=*
- FORCE_COLOR=1 # For some reason on Windows colors support is not detected
before_script:
# Ensure Python 2 in Windows enviroment (Ruby is already preinstalled)
- |
Expand Down
12 changes: 9 additions & 3 deletions lib/classes/CLI.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,10 @@ describe('CLI', () => {
});

it('should print general --help to stdout', (done) => {
exec(`${this.serverlessExec} --help`, (err, stdout) => {
exec(`${this.serverlessExec} --help`, (err, stdout, stderr) => {
if (err) {
process.stdout.write(stdout);
process.stderr.write(stderr);
done(err);
return;
}
Expand All @@ -647,8 +649,10 @@ describe('CLI', () => {
});

it('should print command --help to stdout', (done) => {
exec(`${this.serverlessExec} deploy --help`, (err, stdout) => {
exec(`${this.serverlessExec} deploy --help`, (err, stdout, stderr) => {
if (err) {
process.stdout.write(stdout);
process.stderr.write(stderr);
done(err);
return;
}
Expand All @@ -660,8 +664,10 @@ describe('CLI', () => {
});

it('should print help --verbose to stdout', (done) => {
exec(`${this.serverlessExec} help --verbose`, (err, stdout) => {
exec(`${this.serverlessExec} help --verbose`, (err, stdout, stderr) => {
if (err) {
process.stdout.write(stdout);
process.stderr.write(stderr);
done(err);
return;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/classes/Error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,14 @@ describe('Error', () => {
});

it('should re-throw error when handling raises an exception itself', () => {
const handlingError = new Error('an unexpected error');

let thrownError = null;
try {
logError('INVALID INPUT');
} catch (e) {
thrownError = e;
}

expect(thrownError).to.deep.equal(handlingError);
expect(thrownError.message).to.equal('INVALID INPUT');
});
});

Expand Down
44 changes: 19 additions & 25 deletions lib/classes/PluginManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ describe('PluginManager', () => {
it('should log a warning when trying to load unknown plugin with help flag', () => {
const consoleLogStub = sinon.stub(pluginManager.serverless.cli, 'log').returns();
const servicePlugins = ['ServicePluginMock3', 'ServicePluginMock1'];
const servicePluginMock1 = new ServicePluginMock1();

pluginManager.setCliOptions({ help: true });
pluginManager.loadPlugins(servicePlugins);

expect(pluginManager.plugins).to.contain(servicePluginMock1);
expect(pluginManager.plugins
.some(plugin => plugin instanceof ServicePluginMock1)).to.equal(true);
expect(consoleLogStub.calledOnce).to.equal(true);
});

Expand Down Expand Up @@ -722,9 +722,7 @@ describe('PluginManager', () => {
mockRequire.stop('ServicePluginMock1');
});
});
describe('#asyncPluginInit()', function () {
this.timeout(5000);

describe('#asyncPluginInit()', () => {
it('should call async init on plugins that have it', () => {
const plugin1 = new ServicePluginMock1();
plugin1.asyncInit = sinon.stub().returns(BbPromise.resolve());
Expand All @@ -735,9 +733,7 @@ describe('PluginManager', () => {
});
});

describe('#loadAllPlugins()', function () {
this.timeout(5000);

describe('#loadAllPlugins()', () => {
beforeEach(function () { // eslint-disable-line prefer-arrow-callback
mockRequire('ServicePluginMock1', ServicePluginMock1);
mockRequire('ServicePluginMock2', ServicePluginMock2);
Expand All @@ -757,13 +753,12 @@ describe('PluginManager', () => {
const servicePlugins = ['ServicePluginMock1', 'ServicePluginMock2'];
pluginManager.loadAllPlugins(servicePlugins);

const servicePluginMock1 = new ServicePluginMock1();
const servicePluginMock2 = new ServicePluginMock2();
const enterprisePluginMock = new EnterprisePluginMock();

expect(pluginManager.plugins).to.contain(servicePluginMock1);
expect(pluginManager.plugins).to.contain(servicePluginMock2);
expect(pluginManager.plugins).to.contain(enterprisePluginMock);
expect(pluginManager.plugins
.some(plugin => plugin instanceof ServicePluginMock1)).to.equal(true);
expect(pluginManager.plugins
.some(plugin => plugin instanceof ServicePluginMock2)).to.equal(true);
expect(pluginManager.plugins
.some(plugin => plugin instanceof EnterprisePluginMock)).to.equal(true);
// note: this test will be refactored as the Create plugin will be moved
// to another directory
expect(pluginManager.plugins.length).to.be.above(2);
Expand Down Expand Up @@ -815,11 +810,10 @@ describe('PluginManager', () => {
const servicePlugins = ['ServicePluginMock1', 'ServicePluginMock2'];
pluginManager.loadServicePlugins(servicePlugins);

const servicePluginMock1 = new ServicePluginMock1();
const servicePluginMock2 = new ServicePluginMock2();

expect(pluginManager.plugins).to.contain(servicePluginMock1);
expect(pluginManager.plugins).to.contain(servicePluginMock2);
expect(pluginManager.plugins
.some(plugin => plugin instanceof ServicePluginMock1)).to.equal(true);
expect(pluginManager.plugins
.some(plugin => plugin instanceof ServicePluginMock2)).to.equal(true);
});

it('should not error if plugins = null', () => {
Expand Down Expand Up @@ -1590,20 +1584,20 @@ describe('PluginManager', () => {

const commands = pluginManager.getCommands();
expect(commands).to.have.a.property('mycmd');
expect(commands).to.have.a.deep.property('mycmd.commands.mysubcmd');
expect(commands).to.have.a.deep.property('mycmd.commands.spawncmd');
expect(commands).to.have.a.nested.property('mycmd.commands.mysubcmd');
expect(commands).to.have.a.nested.property('mycmd.commands.spawncmd');
// Check for omitted entrypoints
expect(commands).to.not.have.a.property('myep');
expect(commands).to.not.have.a.deep.property('myep.commands.mysubep');
expect(commands).to.not.have.a.deep.property('mycmd.commands.spawnep');
expect(commands).to.not.have.a.nested.property('myep.commands.mysubep');
expect(commands).to.not.have.a.nested.property('mycmd.commands.spawnep');
});

it('should return aliases', () => {
pluginManager.addPlugin(AliasPluginMock);

const commands = pluginManager.getCommands();
expect(commands).to.have.a.property('on')
.that.has.a.deep.property('commands.premise');
.that.has.a.nested.property('commands.premise');
expect(commands).to.have.a.property('premise');
});
});
Expand Down
8 changes: 4 additions & 4 deletions lib/classes/Service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,10 @@ describe('Service', () => {
const serverless = new Serverless();
const noService = new Service(serverless);

return expect(noService.load()).to.eventually.resolve;
return expect(noService.load()).to.be.fulfilled;
});

it('should load serverless.yml from filesystem', function () {
this.timeout(3000);
it('should load serverless.yml from filesystem', () => {
const SUtils = new Utils();
const serverlessYml = {
service: 'new-service',
Expand Down Expand Up @@ -735,7 +734,8 @@ describe('Service', () => {
}

it(`should not throw an error if http event is absent and
stage contains only alphanumeric, underscore and hyphen`, () => {
stage contains only alphanumeric, underscore and hyphen`, function () {
this.timeout(10000); // Occasionally times out with default settings
const SUtils = new Utils();
const serverlessYml = {
service: 'new-service',
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/Utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('Utils', () => {

expect(() => {
serverless.utils.readFileSync(tmpFilePath);
}).to.throw(new RegExp('YAMLException:.*invalid.yml'));
}).to.throw(/.*invalid.yml/);
});
});

Expand Down
10 changes: 8 additions & 2 deletions lib/classes/Variables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const slsError = require('./Error');
const Utils = require('../../lib/classes/Utils');
const Variables = require('../../lib/classes/Variables');
const { getTmpDirPath } = require('../../tests/utils/fs');
const { skipOnWindowsDisabledSymlinks } = require('../../tests/utils/misc');

BbPromise.longStackTraces(true);

Expand Down Expand Up @@ -1669,13 +1670,18 @@ module.exports = {
.should.become('hello world');
});

it('should populate symlinks', () => {
it('should populate symlinks', function () {
const SUtils = new Utils();
const tmpDirPath = getTmpDirPath();
const realFilePath = path.join(tmpDirPath, 'someFile');
const symlinkPath = path.join(tmpDirPath, 'refSomeFile');
SUtils.writeFileSync(realFilePath, 'hello world');
fse.ensureSymlinkSync(realFilePath, symlinkPath);
try {
fse.ensureSymlinkSync(realFilePath, symlinkPath);
} catch (error) {
skipOnWindowsDisabledSymlinks(error, this);
throw error;
}
serverless.config.update({ servicePath: tmpDirPath });
return serverless.variables.getValueFromFile('file(./refSomeFile)')
.should.become('hello world')
Expand Down
6 changes: 3 additions & 3 deletions lib/classes/YamlParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('YamlParser', () => {
serverless.utils.writeFileSync(path.join(tmpDirPath, 'test.yml'), testYml);

return expect(serverless.yamlParser.parse(path.join(tmpDirPath, 'test.yml')))
.to.eventually.have.deep.property('main.foo').to.equal('bar');
.to.eventually.have.nested.property('main.foo').to.equal('bar');
});

it('should parse a .yml file with JSON-REF to JSON', () => {
Expand All @@ -67,7 +67,7 @@ describe('YamlParser', () => {
serverless.utils.writeFileSync(path.join(tmpDirPath, 'test.yml'), testYml);

return expect(serverless.yamlParser.parse(path.join(tmpDirPath, 'test.yml')))
.to.eventually.have.deep.property('main.foo').to.equal('bar');
.to.eventually.have.nested.property('main.foo').to.equal('bar');
});

it('should parse a .yml file with recursive JSON-REF', () => {
Expand All @@ -92,7 +92,7 @@ describe('YamlParser', () => {
serverless.utils.writeFileSync(path.join(tmpDirPath, 'one.yml'), oneYml);

return expect(serverless.yamlParser.parse(path.join(tmpDirPath, 'one.yml')))
.to.eventually.have.deep.property('one.two.foo').to.equal('bar');
.to.eventually.have.nested.property('one.two.foo').to.equal('bar');
});
});
});
10 changes: 5 additions & 5 deletions lib/plugins/aws/common/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,34 @@ describe('AwsCommon', () => {

describe('commands', () => {
it('should be only entrypoints', () => {
expect(awsCommon.commands).to.have.deep.property('aws.type', 'entrypoint');
expect(awsCommon.commands).to.have.nested.property('aws.type', 'entrypoint');
});

describe('aws:common:validate', () => {
it('should exist', () => {
expect(awsCommon.commands)
.to.have.deep.property('aws.commands.common.commands.validate');
.to.have.nested.property('aws.commands.common.commands.validate');
});
});

describe('aws:common:cleanupTempDir', () => {
it('should exist', () => {
expect(awsCommon.commands)
.to.have.deep.property('aws.commands.common.commands.cleanupTempDir');
.to.have.nested.property('aws.commands.common.commands.cleanupTempDir');
});
});

describe('aws:common:moveArtifactsToPackage', () => {
it('should exist', () => {
expect(awsCommon.commands)
.to.have.deep.property('aws.commands.common.commands.moveArtifactsToPackage');
.to.have.nested.property('aws.commands.common.commands.moveArtifactsToPackage');
});
});

describe('aws:common:moveArtifactsToTemp', () => {
it('should exist', () => {
expect(awsCommon.commands)
.to.have.deep.property('aws.commands.common.commands.moveArtifactsToTemp');
.to.have.nested.property('aws.commands.common.commands.moveArtifactsToTemp');
});
});
});
Expand Down
3 changes: 1 addition & 2 deletions lib/plugins/aws/deployFunction/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ describe('AwsDeployFunction', () => {
let awsDeployFunction;
let cryptoStub;

beforeEach(function () {
this.timeout(3000);
beforeEach(() => {
serverless = new Serverless();
serverless.servicePath = true;
serverless.service.environment = {
Expand Down