Skip to content

Commit

Permalink
Fix tests with Serverless v3
Browse files Browse the repository at this point in the history
The new serverless class must have 3 options for its argument.

```
// before
serverless = new Serverless();

// after
serverless = new Serverless({ commands: ['print'], options: {}, serviceDir: null });
```

Also:
- remove useless `prettier-eslint-cli` which isn't compatible with ESLint 8 and also isn't necessary (we can use `prettier` directly)
- move all `*.tests.js` file into the `tests/` folder (easier to find them)
- require node 12
  • Loading branch information
j0k3r committed Feb 3, 2022
1 parent c667301 commit 6975610
Show file tree
Hide file tree
Showing 26 changed files with 11,268 additions and 19,469 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- windows-latest
- ubuntu-18.04
node:
- "10"
- "12"
- "14"
- "16"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -97,3 +97,34 @@ jobs:

- name: "Run tests"
run: "npm run test"

serverless-v2:
runs-on: ${{ matrix.os }}
name: Node.js ${{ matrix.node }} on ${{ matrix.os }} with Serverless v2

strategy:
matrix:
os:
- ubuntu-20.04
node:
- "14"

steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: "Install Node.js"
uses: actions/setup-node@v2
with:
node-version: "${{ matrix.node }}"

- name: "Install Serverless v2"
run: npm install serverless@2

- name: "Install dependencies"
run: npm ci

- name: "Run tests"
run: "npm run test"
2 changes: 1 addition & 1 deletion examples/typescript/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
externals: [nodeExternals()],
devtool: 'source-map',
resolve: {
extensions: [ '.js', '.jsx', '.json', '.ts', '.tsx' ]
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
},
output: {
libraryTarget: 'commonjs2',
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ServerlessWebpack {
},
package: {
type: 'entrypoint',
lifecycleEvents: [ 'packExternalModules', 'packageModules', 'copyExistingArtifacts' ]
lifecycleEvents: ['packExternalModules', 'packageModules', 'copyExistingArtifacts']
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/packExternalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function getProdModules(externalModules, packagePath, nodeModulesRelativeDir, de
moduleVersion = _.get(_.get(originInfo, 'dependencies', {})[module.external], 'version');
if (!moduleVersion) {
// eslint-disable-next-line lodash/path-style
moduleVersion = _.get(dependencyGraph, [ 'dependencies', module.external, 'version' ]);
moduleVersion = _.get(dependencyGraph, ['dependencies', module.external, 'version']);
}
if (!moduleVersion) {
this.serverless.cli.log(`WARNING: Could not determine version of module ${module.external}`);
Expand Down Expand Up @@ -378,12 +378,12 @@ module.exports = {
.then(() =>
hasPackageLock
? BbPromise.fromCallback(callback =>
fse.copy(
path.join(compositeModulePath, packager.lockfileName),
path.join(modulePath, packager.lockfileName),
callback
fse.copy(
path.join(compositeModulePath, packager.lockfileName),
path.join(modulePath, packager.lockfileName),
callback
)
)
)
: BbPromise.resolve()
)
.tap(
Expand Down
2 changes: 1 addition & 1 deletion lib/packagers/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class NPM {
static runScripts(cwd, scriptNames) {
const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
return BbPromise.mapSeries(scriptNames, scriptName => {
const args = [ 'run', scriptName ];
const args = ['run', scriptName];

return Utils.spawnProcess(command, args, { cwd });
}).return();
Expand Down
6 changes: 3 additions & 3 deletions lib/packagers/yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Yarn {

static getProdDependencies(cwd, depth) {
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn';
const args = [ 'list', `--depth=${depth || 1}`, '--json', '--production' ];
const args = ['list', `--depth=${depth || 1}`, '--json', '--production'];

// If we need to ignore some errors add them here
const ignoredYarnErrors = [];
Expand Down Expand Up @@ -123,7 +123,7 @@ class Yarn {
}

const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn';
const args = [ 'install', '--non-interactive' ];
const args = ['install', '--non-interactive'];

// Convert supported packagerOptions
if (!packagerOptions.noFrozenLockfile) {
Expand All @@ -147,7 +147,7 @@ class Yarn {
static runScripts(cwd, scriptNames) {
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn';
return BbPromise.mapSeries(scriptNames, scriptName => {
const args = [ 'run', scriptName ];
const args = ['run', scriptName];

return Utils.spawnProcess(command, args, { cwd });
}).return();
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Utils', () => {

describe('splitLines', () => {
it('should split on new line characters', () => {
expect(Utils.splitLines('a\r\nb\nc')).to.deep.equal([ 'a', 'b', 'c' ]);
expect(Utils.splitLines('a\r\nb\nc')).to.deep.equal(['a', 'b', 'c']);
});
});
});
4 changes: 2 additions & 2 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { getAllNodeFunctions, isNodeRuntime } = require('./utils');
* This should cover most of the cases. For complex setups the user should
* build his own entries with help of the other exports.
*/
const preferredExtensions = [ '.js', '.ts', '.jsx', '.tsx' ];
const preferredExtensions = ['.js', '.ts', '.jsx', '.tsx'];

module.exports = {
validate() {
Expand Down Expand Up @@ -249,7 +249,7 @@ module.exports = {
const entry = path.relative('.', value);
const entryFile = _.replace(entry, new RegExp(`${path.extname(entry)}$`), '');

const entryFuncs = _.filter(allEntryFunctions, [ 'handlerFile', entryFile ]);
const entryFuncs = _.filter(allEntryFunctions, ['handlerFile', entryFile]);
if (_.isEmpty(entryFuncs)) {
// We have to make sure that for each entry there is an entry function item.
entryFuncs.push({});
Expand Down
Loading

0 comments on commit 6975610

Please sign in to comment.