Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (allFunctions.indexOf(functionName) >= 0) {
setEnv(serverless, functionName);
Object.assign(config, { testRegex: `${functionName}\\.test\\.[jt]s$` });
} else {
return reject(`Function "${functionName}" not found`);
}
} else {
const functionsRegex = allFunctions.map(name => `${name}\\.test\\.[jt]s$`).join('|');
Object.assign(config, { testRegex: functionsRegex });
}
}
// eslint-disable-next-line dot-notation
process.env['SERVERLESS_TEST_ROOT'] = serverless.config.servicePath;
return runCLI(config, [serverless.config.servicePath])
.then((output) => {
if (output.results.success) {
resolve(output);
} else {
reject(output.results);
}
})
.catch(e => reject(e));
});
function unitTest(projectDir) {
const configPath = path.join(projectDir, 'jest.config.js');
const jestConfig = fs.pathExistsSync(configPath)
? require(configPath)
: require('./webpack/jest-config');
const argv = {config: JSON.stringify(jestConfig)};
require('jest').runCLI(argv, [projectDir]); // BUG: should be tests/unit?
}
runJestTest(path) {
const options = {
projects: [__dirname],
silent: true,
testPathPattern: ["tests/scenarios/" + this.scenario + "/" + path.replace(/\//g, "\\/")],
modulePathIgnorePatterns: ["dist/"],
};
jest.runCLI(options, options.projects)
.then(success => {
console.log(`[test-runner] Test ${path} was run successfully`);
this.testResults.push(success.results);
this.failedTestSuites += success.results.numFailedTestSuites;
})
.catch(failure => {
console.error(`[test-runner] Error running test ${path} : ${failure}`);
});
}
run: async function(args) {
try {
const jestResult = await jest.runCLI(args, [process.cwd()]);
if (!jestResult.results.success) {
throw TranslationService.getMessage(MESSAGES.UNIT_TEST.TEST_FAILED);
}
} catch (error) {
throw TranslationService.getMessage(MESSAGES.UNIT_TEST.TEST_FAILURES_PRESENT);
}
}
};
export function test(command: any) {
setNodeEnv('test');
genPackageEntry({
outputPath: PACKAGE_ENTRY_FILE
});
const config = {
rootDir: ROOT,
watch: command.watch,
config: JEST_CONFIG_FILE,
clearCache: command.clearCache
} as any;
runCLI(config, [ROOT])
.then(response => {
if (!response.results.success && !command.watch) {
process.exit(1);
}
})
.catch(err => {
console.log(err);
if (!command.watch) {
process.exit(1);
}
});
}
async function test() {
const opts = {
collectCoverage: true,
coverageDirectory: 'build/coverage',
collectCoverageFrom: ['src/**', '!src/zone.js', '!src/luxonFilled.js'],
ci: !!process.env.CI,
testEnvironment: 'node'
};
if (process.env.LIMIT_JEST) {
opts.maxWorkers = 4;
}
return jest.runCLI(opts, ['./test']);
}
if (options.findRelatedTests) {
const parsedTests = options.findRelatedTests.split(',').map(s => s.trim());
config._.push(...parsedTests);
config.findRelatedTests = true;
}
if (options.clearCache) {
config.clearCache = true;
}
if (options.reporters && options.reporters.length > 0) {
config.reporters = options.reporters;
}
return from(runCLI(config, [options.jestConfig])).pipe(
map(results => {
return {
success: results.results.success
};
})
);
}
public run(jestConfig: Configuration, projectRoot: string, fileNameUnderTest?: string): Promise {
jestConfig.reporters = [];
const config = JSON.stringify(jestConfig);
this.log.trace(`Invoking Jest with config ${config}`);
if (fileNameUnderTest) {
this.log.trace(`Only running tests related to ${fileNameUnderTest}`);
}
return runCLI({
...(fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true}),
config,
runInBand: true,
silent: true
}, [projectRoot]);
}
}
Kefir.stream(emitter => {
process.env.NODE_ENV = 'test';
process.env.BABEL_ENV = 'test';
emitter.value(actions.testRun.request());
jest.runCLI(buildArgv(argv), projects).then(({ results }) => {
if (results.success) {
emitter.value(actions.testRun.success());
} else {
emitter.value(actions.testRun.failure());
}
emitter.value(actions.shutdown.request());
});
})
)