mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Skip with notice functionality
This commit is contained in:
parent
2bc1b2925c
commit
194a12e799
@ -11,7 +11,9 @@ const os = require('os');
|
||||
const Spec = require('mocha/lib/reporters/spec');
|
||||
const Runner = require('mocha/lib/runner');
|
||||
const { ensureDirSync, removeSync } = require('fs-extra');
|
||||
const chalk = require('chalk');
|
||||
const { tmpDirCommonPath } = require('../tests/utils/fs');
|
||||
const { skippedWithNotice } = require('../tests/utils/misc');
|
||||
|
||||
// Ensure faster tests propagation
|
||||
// It's to expose errors otherwise hidden by race conditions
|
||||
@ -83,6 +85,29 @@ module.exports = class ServerlessSpec extends Spec {
|
||||
});
|
||||
|
||||
runner.on('end', () => {
|
||||
// Output eventual skip notices
|
||||
if (skippedWithNotice.length) {
|
||||
const resolveTestName = test => {
|
||||
const names = [test.title];
|
||||
let parent = test.parent;
|
||||
while (parent) {
|
||||
if (parent.title) names.push(parent.title);
|
||||
parent = parent.parent;
|
||||
}
|
||||
return `${chalk.cyan(names.reverse().join(': '))} (in: ${chalk.grey(
|
||||
test.file.slice(process.cwd().length + 1)
|
||||
)})`;
|
||||
};
|
||||
process.stdout.write(
|
||||
' Notice: Some tests were skipped due to following environment issues:' +
|
||||
`\n\n - ${skippedWithNotice
|
||||
.map(
|
||||
meta => `${resolveTestName(meta.context.test)}\n\n ${chalk.red(meta.reason)}\n`
|
||||
)
|
||||
.join('\n - ')}\n\n`
|
||||
);
|
||||
}
|
||||
|
||||
// Cleanup temporary homedir
|
||||
try {
|
||||
removeSync(tmpDirCommonPath);
|
||||
|
||||
@ -4,6 +4,7 @@ const path = require('path');
|
||||
const fse = require('fs-extra');
|
||||
const BbPromise = require('bluebird');
|
||||
const { execSync } = require('child_process');
|
||||
const chalk = require('chalk');
|
||||
const { replaceTextInFile } = require('../fs');
|
||||
|
||||
const logger = console;
|
||||
@ -102,6 +103,20 @@ function persistentRequest(...args) {
|
||||
});
|
||||
}
|
||||
|
||||
const skippedWithNotice = [];
|
||||
|
||||
function skipWithNotice(context, reason) {
|
||||
if (process.env.CI) return; // Do not tolerate skips in CI environment
|
||||
skippedWithNotice.push({ context, reason });
|
||||
process.stdout.write(chalk.yellow(`\n Skipped due to: ${chalk.red(reason)}\n\n`));
|
||||
context.skip();
|
||||
}
|
||||
|
||||
function skipOnWindowsDisabledSymlinks(error, context) {
|
||||
if (error.code !== 'EPERM' || process.platform !== 'win32') return;
|
||||
skipWithNotice(context, 'Missing admin rights to create symlinks');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
logger,
|
||||
region,
|
||||
@ -115,4 +130,7 @@ module.exports = {
|
||||
createTestService,
|
||||
getFunctionLogs,
|
||||
persistentRequest,
|
||||
skippedWithNotice,
|
||||
skipWithNotice,
|
||||
skipOnWindowsDisabledSymlinks,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user