Skip to content

Commit

Permalink
Fix serverless framework executor to throw error when serverless comm…
Browse files Browse the repository at this point in the history
…and fails
  • Loading branch information
lucasvieirasilva committed Nov 23, 2022
1 parent e4128cf commit f144494
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/nx-python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.10.3] - 2022-11-23

### Fixed

- Fix serverless framework executor to throw error when serverless command fails.

## [1.10.2] - 2022-09-27

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-python/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nxlv/python",
"version": "1.10.2",
"version": "1.10.3",
"description": "Custom NX Plugin to support the Python language",
"main": "src/index.js",
"generators": "./generators.json",
Expand Down
39 changes: 39 additions & 0 deletions packages/nx-python/src/executors/sls-deploy/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ describe('Serverless Framework Deploy Executor', () => {
fsMock({
'apps/app/dist/test.whl': 'abc123'
})
spawnSyncMock.mockReturnValue({
status: 0
})

const output = await executor(
{
Expand All @@ -91,10 +94,46 @@ describe('Serverless Framework Deploy Executor', () => {
expect(output.success).toBe(true);
});

it('should run serverless framework command with error status code', async () => {
fsMock({
'apps/app/dist/test.whl': 'abc123'
})
spawnSyncMock.mockReturnValue({
status: 1
})

const output = await executor(
{
stage: 'dev',
verbose: false,
force: false
},
context
);
expect(spawnSyncMock).toHaveBeenCalledWith(
'npx',
[
'sls',
'deploy',
'--stage',
'dev'
],
{
cwd: 'apps/app',
stdio: 'inherit',
shell: false
}
)
expect(output.success).toBe(false);
});

it('should run serverless framework command using npx with verbose and force', async () => {
fsMock({
'apps/app/dist/test.whl': 'abc123'
})
spawnSyncMock.mockReturnValue({
status: 0
})

const output = await executor(
{
Expand Down
8 changes: 6 additions & 2 deletions packages/nx-python/src/executors/sls-deploy/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ export default async function executor(
const deployArgs = ['sls', 'deploy', '--stage', options.stage]
.concat(options.verbose ? ['--verbose'] : [])
.concat(options.force ? ['--force'] : [])
spawn.sync(executable, deployArgs, {
const result = spawn.sync(executable, deployArgs, {
cwd: cwd,
shell: false,
stdio: 'inherit'
stdio: 'inherit',
});

if (result.status !== 0) {
throw new Error(`Serverless deploy failed`);
}

return {
success: true,
};
Expand Down
34 changes: 34 additions & 0 deletions packages/nx-python/src/executors/sls-package/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ describe('Serverless Framework Package Executor', () => {
fsMock({
'apps/app/dist/test.whl': 'abc123'
})
spawnSyncMock.mockReturnValue({
status: 0
})

const output = await executor(
{
Expand All @@ -84,4 +87,35 @@ describe('Serverless Framework Package Executor', () => {
)
expect(output.success).toBe(true);
});

it('should run serverless framework command with error', async () => {
fsMock({
'apps/app/dist/test.whl': 'abc123'
})
spawnSyncMock.mockReturnValue({
status: 1
})

const output = await executor(
{
stage: 'dev'
},
context
);
expect(spawnSyncMock).toHaveBeenCalledWith(
'npx',
[
'sls',
'package',
'--stage',
'dev'
],
{
cwd: 'apps/app',
stdio: 'inherit',
shell: false
}
)
expect(output.success).toBe(false);
});
});
6 changes: 5 additions & 1 deletion packages/nx-python/src/executors/sls-package/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ export default async function executor(

const executable = 'npx'
const deployArgs = ['sls', 'package', '--stage', options.stage]
spawn.sync(executable, deployArgs, {
const result = spawn.sync(executable, deployArgs, {
cwd: cwd,
shell: false,
stdio: 'inherit'
});

if (result.status !== 0) {
throw new Error(`Serverless package failed`);
}

return {
success: true,
};
Expand Down

0 comments on commit f144494

Please sign in to comment.