Skip to content

Commit

Permalink
fix: Fix handling of pre-releases in frameworkVersion validation
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Sep 2, 2020
1 parent 7aad819 commit c0fb04a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/classes/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class Service {
// basic service level validation
const version = this.serverless.utils.getVersion();
const ymlVersion = serverlessFile.frameworkVersion;
if (ymlVersion && !semver.satisfies(version, ymlVersion)) {
if (
ymlVersion &&
version !== ymlVersion &&
!semver.satisfies(semver.coerce(version).raw, ymlVersion)
) {
const errorMessage = [
`The Serverless version (${version}) does not satisfy the`,
` "frameworkVersion" (${ymlVersion}) in ${this.serviceFilename}`,
Expand Down
32 changes: 26 additions & 6 deletions lib/classes/Service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,32 @@ describe('Service', () => {
).to.eventually.be.rejected.and.have.property('code', 'FRAMEWORK_VERSION_MISMATCH'));

it('should pass if frameworkVersion is satisfied', () =>
fixtures.extend('configTypeYml', { frameworkVersion: version }).then(fixturePath =>
runServerless({
cwd: fixturePath,
cliArgs: ['print'],
})
));
fixtures
.extend('configTypeYml', { frameworkVersion: version })
.then(fixturePath =>
runServerless({
cwd: fixturePath,
cliArgs: ['print'],
})
)
.then(() =>
fixtures.extend('configTypeYml', { frameworkVersion: '*' }).then(fixturePath =>
runServerless({
cwd: fixturePath,
cliArgs: ['print'],
})
)
)
.then(() =>
fixtures
.extend('configTypeYml', { frameworkVersion: version.split('.')[0] })
.then(fixturePath =>
runServerless({
cwd: fixturePath,
cliArgs: ['print'],
})
)
));
});

describe('#mergeArrays', () => {
Expand Down

0 comments on commit c0fb04a

Please sign in to comment.