Skip to content

Commit 26b4dc5

Browse files
steffyPwhummer
andauthored
CI update: node 18 + run tests for serverless v2 and v3 (#220)
Co-authored-by: Waldemar Hummer <waldemar.hummer@gmail.com>
1 parent 102fe13 commit 26b4dc5

4 files changed

Lines changed: 34 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,47 @@ jobs:
1010
serverless-localstack-test:
1111
name: Serverless LocalStack CI
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
sls-major-version: ["2", "3"]
1316
steps:
1417
- name: Checkout repository
1518
uses: actions/checkout@v3
1619

1720
- name: Setup NodeJS
18-
uses: actions/setup-node@v2
21+
uses: actions/setup-node@v3
1922
with:
20-
node-version: '12'
23+
node-version: '18'
2124

2225
- name: Cache node modules
23-
uses: actions/cache@v2
26+
uses: actions/cache@v3
2427
env:
25-
cache-name: cache-node-modules
28+
cache-name: cache-node-modules-v${{ matrix.sls-major-version }}
2629
with:
2730
path: ~/.npm
28-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
31+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.sls-major-version }}-${{ hashFiles('**/package-lock.json') }}
2932
restore-keys: |
30-
${{ runner.os }}-build-${{ env.cache-name }}-
31-
${{ runner.os }}-build-
32-
${{ runner.os }}-
33+
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.sls-major-version }}-
34+
35+
- name: Install deps
36+
run: |
37+
npm install
38+
39+
- name: Update SLS version to v3
40+
if: ${{ matrix.sls-major-version == '3' }}
41+
run: |
42+
npm install serverless@3
43+
44+
- name: Check installed version
45+
env:
46+
EXPECTED_SLS_MAJOR_VERSION: ${{ matrix.sls-major-version }}
47+
run : |
48+
installed_sls_version=$(npm list | grep serverless@ | sed -E 's/.*serverless@(.*)/\1/')
49+
echo "installed serverless version: ${installed_sls_version}"
50+
if [ "${installed_sls_version:0:1}" != ${EXPECTED_SLS_MAJOR_VERSION} ]; then
51+
echo "expected version ${EXPECTED_SLS_MAJOR_VERSION}, but installed ${installed_sls_version}"
52+
exit 1
53+
fi
3354
3455
- name: Start LocalStack
3556
run: |
@@ -38,10 +59,6 @@ jobs:
3859
localstack start -d
3960
localstack wait -t 30
4061
41-
- name: Install deps
42-
run: |
43-
npm ci
44-
4562
- name: Run Lint and Test
4663
run: |
4764
set -e

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
"test:watch": "JASMINE_CONFIG_PATH=spec/support/jasmine.json jasmine",
1111
"test:integration": "JASMINE_CONFIG_PATH=spec/support/jasmine_integration.json jasmine",
1212
"test:integration:watch": "JASMINE_CONFIG_PATH=spec/support/jasmine_integration.json nodemon -L -i spec/integrate ./node_modules/.bin/jasmine",
13-
"test:cover": "jasmine --coverage",
14-
"prepublish": "npm run test",
15-
"preversion": "npm run test"
13+
"test:cover": "jasmine --coverage"
1614
},
1715
"repository": {
1816
"type": "git",

spec/integration/integration.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const AWS = require('aws-sdk');
88
// Set the region and endpoint in the config for LocalStack
99
AWS.config.update({
1010
region: 'us-east-1',
11-
endpoint: 'http://localhost:4566'
11+
endpoint: 'http://127.0.0.1:4566'
1212
});
1313
AWS.config.credentials = new AWS.Credentials({
1414
accessKeyId: 'test',

spec/unit/index.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("LocalstackPlugin", () => {
3232

3333
beforeEach(() => {
3434
sandbox = sinon.createSandbox();
35-
serverless = new Serverless();
35+
serverless = new Serverless({commands: ['deploy'], options: {}});
3636
awsProvider = new AwsProvider(serverless, {});
3737
awsConfig = new AWS.Config();
3838
AWS.config = awsConfig;
@@ -176,7 +176,8 @@ describe("LocalstackPlugin", () => {
176176
});
177177
expect(request.called).to.be.true;
178178
let templateUrl = request.firstCall.args[2].TemplateURL;
179-
expect(templateUrl).to.startsWith(`${config.host}`);
179+
// url should either start with 'http://localhost' or 'http://127.0.0.1
180+
expect(templateUrl).to.satisfy((url) => url.startsWith(`${config.host}`) || url.startsWith('http://127.0.0.1'));
180181
});
181182

182183
it('should not send validateTemplate calls to localstack', async () => {

0 commit comments

Comments
 (0)