forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocharc-common.cjs
89 lines (75 loc) · 3.31 KB
/
mocharc-common.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
"use strict";
const { existsSync } = require("fs");
const path = require("path");
function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testReportPrefix) {
const moduleDir = `${packageDir}/node_modules`;
const requiredModules = [
// General mocha setup e.g. suppresses console.log,
// This has to be before others (except logger) so that registerMochaTestWrapperFuncs is available
"@fluid-internal/mocha-test-setup",
"source-map-support/register",
...(additionalRequiredModules ? additionalRequiredModules : []),
];
// mocha install node_modules directory might not be the same as the module required because of hoisting
// We need to give the full path in that case.
// TODO: this path mapping might not be necessary once we move to pnpm, since it sets up node_modules differently
// from what Lerna does (all dependencies of a given package show up in its own node_modules folder and just symlink
// to the actual location of the installed package, instead of common dependencies being hoisted to a parent
// node_modules folder and not being present at all in the package's own node_modules).
const requiredModulePaths = requiredModules.map((mod) => {
// Just return if it is path already
if (existsSync(mod) || existsSync(`${mod}.js`)) {
return mod;
}
// Try to find it in the test package's directory
const modulePath = path.join(moduleDir, mod);
if (existsSync(modulePath)) {
return modulePath;
}
// Otherwise keep it as is
return mod;
});
if (process.env.FLUID_TEST_LOGGER_PKG_PATH) {
// Inject implementation of getTestLogger, put it first before mocha-test-setup
requiredModulePaths.unshift(process.env.FLUID_TEST_LOGGER_PKG_PATH);
}
const config = {
"recursive": true,
"require": requiredModulePaths,
"unhandled-rejections": "strict",
// Allow test-only indexes to be imported. Search the FF repo for package.json files with this condition to see example usage.
"node-option": "conditions=allow-ff-test-exports",
// Performance tests benefit from having access to GC, and memory tests require it.
// Exposing it here avoids all packages which do perf testing from having to expose it.
"v8-expose-gc": true,
};
if (process.env.FLUID_TEST_TIMEOUT !== undefined) {
config["timeout"] = process.env.FLUID_TEST_TIMEOUT;
}
const packageJson = require(`${packageDir}/package.json`);
config["reporter"] = `mocha-multi-reporters`;
// See https://www.npmjs.com/package/mocha-multi-reporters#cmroutput-option
const outputFilePrefix = testReportPrefix !== undefined ? `${testReportPrefix}-` : "";
console.log(
`Writing test results relative to package to nyc/${outputFilePrefix}junit-report.xml and nyc/${outputFilePrefix}junit-report.json`,
);
const suiteName =
testReportPrefix !== undefined
? `${packageJson.name} - ${testReportPrefix}`
: packageJson.name;
config["reporter-options"] = [
`configFile=${path.join(
__dirname,
"test-config.json",
)},cmrOutput=xunit+output+${outputFilePrefix}:mocha-json-output-reporter+output+${outputFilePrefix}:xunit+suiteName+${suiteName}`,
];
if (process.env.FLUID_TEST_FORBID_ONLY !== undefined) {
config["forbid-only"] = true;
}
return config;
}
module.exports = getFluidTestMochaConfig;