Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(CLI):
doctor
command for modern handling of deprecations
- Loading branch information
Showing
8 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const fsp = require('fs').promises; | ||
const { writeText, log } = require('@serverless/utils/log'); | ||
const healthStatusFilename = require('../lib/utils/health-status-filename'); | ||
|
||
module.exports = async () => { | ||
const healthStatus = await (async () => { | ||
try { | ||
return await fsp.readFile(healthStatusFilename); | ||
} catch (error) { | ||
if (error.code === 'ENOENT') return null; | ||
throw error; | ||
} | ||
})(); | ||
|
||
if (healthStatus) writeText(healthStatus); | ||
else log.notice('No deprecations were reported in the last command'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const os = require('os'); | ||
|
||
module.exports = path.resolve(os.homedir(), '.serverless/last-command-health-status'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const path = require('path'); | ||
const spawn = require('child-process-ext/spawn'); | ||
const { expect } = require('chai'); | ||
|
||
chai.use(require('chai-as-promised')); | ||
|
||
const serverlessPath = path.resolve(__dirname, '../../../scripts/serverless.js'); | ||
|
||
describe('test/unit/commands/doctor.test.js', async () => { | ||
before(() => { | ||
process.env.SLS_DEPRECATION_NOTIFICATION_MODE = 'warn:summary'; | ||
process.env.SLS_DEV_LOG_MODE = '3'; | ||
}); | ||
|
||
it('should print health status after command which triggered deprecation', async () => { | ||
// Trigger deprecation | ||
await spawn('node', [serverlessPath, 'config', '--foo']); | ||
|
||
// Gather Health status | ||
expect(String((await spawn('node', [serverlessPath, 'doctor'])).stdoutBuffer)).to.include( | ||
'deprecation triggered in the last command' | ||
); | ||
}); | ||
|
||
it('should inform of no issues when no health status found', async () => { | ||
// Trigger command that reports no issues | ||
await spawn('node', [serverlessPath, 'config', '--help']); | ||
|
||
// Gather Health status | ||
expect(String((await spawn('node', [serverlessPath, 'doctor'])).stdoutBuffer)).to.be.empty; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters