Skip to content

Commit 95cbf19

Browse files
committed
fixup! Add osls to the tests suite
1 parent 7a8e1cc commit 95cbf19

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

examples/include-external-npm-packages-lock-file/_setup.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
// That file is only used by the e2e tests
44

55
const path = require('path');
6+
const fse = require('fs-extra');
7+
8+
async function replacePluginLockReference(lockPath, pluginPackagePath) {
9+
const lock = await fse.readJson(lockPath);
10+
const pluginPackage = lock.packages['../..'];
11+
const installedPackage = lock.packages['node_modules/serverless-webpack'] || {};
12+
13+
lock.packages[''].devDependencies['serverless-webpack'] = `file:${pluginPackagePath}`;
14+
delete lock.packages['../..'];
15+
lock.packages['node_modules/serverless-webpack'] = {
16+
...pluginPackage,
17+
...installedPackage,
18+
resolved: `file:${pluginPackagePath}`
19+
};
20+
delete lock.packages['node_modules/serverless-webpack'].link;
21+
22+
await fse.writeJson(lockPath, lock, { spaces: 2 });
23+
}
624

725
module.exports = async (originalFixturePath, fixturePath, utils) => {
826
const pluginPath = path.resolve(originalFixturePath, '..', '..');
@@ -16,7 +34,7 @@ module.exports = async (originalFixturePath, fixturePath, utils) => {
1634
utils.replaceInFile(SLS_CONFIG_PATH, '- serverless-webpack', `- ${pluginPath}`),
1735
utils.replaceInFile(WEBPACK_CONFIG_PATH, "'serverless-webpack'", `'${pluginPath}'`),
1836
utils.replaceInFile(PACKAGE_JSON_PATH, 'file:../..', `file:${utils.pluginPackagePath}`),
19-
utils.replaceInFile(LOCK_PATH, '../..', `${utils.pluginPackagePath}`)
37+
replacePluginLockReference(LOCK_PATH, utils.pluginPackagePath)
2038
]);
2139

2240
const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';

lib/validate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ module.exports = {
4747
};
4848

4949
const getEntryExtension = fileName => {
50+
const servicePath = this.serverless.config.servicePath || undefined;
5051
const files = glob.sync(`${fileName}.*`, {
51-
cwd: this.serverless.config.servicePath || undefined,
52+
cwd: servicePath,
5253
nodir: true,
5354
ignore: this.configuration.excludeFiles ? this.configuration.excludeFiles : undefined
5455
});
5556

5657
if (_.isEmpty(files)) {
5758
// If we cannot find any handler we should terminate with an error
5859
throw new this.serverless.classes.Error(
59-
`No matching handler found for '${fileName}' in '${this.serverless.config.servicePath}'. Check your service definition.`
60+
`No matching handler found for '${fileName}' in '${servicePath || process.cwd()}'. Check your service definition.`
6061
);
6162
}
6263

tests/utils.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Utils', () => {
2929
expect(err).toHaveProperty('stderr', 'stderr');
3030
});
3131

32-
it('should print message and stderr', () => {
32+
it('should include cwd, stdout and stderr in toString()', () => {
3333
const err = new Utils.SpawnError('message', 'stdout', 'stderr', { cwd: 'cwd' });
3434

3535
expect(err.toString()).toEqual('message\ncwd: cwd\nstdout:\nstdout\nstderr:\nstderr');

tests/validate.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ describe('validate', () => {
11251125
globMock.sync.mockReturnValue([]);
11261126
expect(() => {
11271127
module.validate();
1128-
}).toThrow(/No matching handler found for/);
1128+
}).toThrow(`No matching handler found for 'module1' in '${process.cwd()}'. Check your service definition.`);
11291129
});
11301130

11311131
it('should throw an exception if `options.function` is defined but not found in entries from serverless.yml', () => {

0 commit comments

Comments
 (0)