@fluid-internal/mocha-test-setup 2.101.1 → 2.103.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.attw.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "ignoreRules": ["cjs-resolves-to-esm"]
3
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @fluid-internal/mocha-test-setup
2
2
 
3
+ ## 2.103.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.102.0
8
+
9
+ Dependency updates only.
10
+
3
11
  ## 2.101.0
4
12
 
5
13
  Dependency updates only.
package/eslint.config.mts CHANGED
@@ -15,6 +15,7 @@ const config: Linter.Config[] = [
15
15
  "@typescript-eslint/no-unsafe-assignment": "off",
16
16
  "@typescript-eslint/no-unsafe-call": "off",
17
17
  "@typescript-eslint/no-unsafe-member-access": "off",
18
+ "import-x/no-nodejs-modules": "off",
18
19
  "unicorn/no-negated-condition": "off",
19
20
  "unicorn/no-null": "off",
20
21
  },
@@ -0,0 +1,36 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Mocha configuration object returned by {@link getFluidTestMochaConfig}.
7
+ */
8
+ export interface FluidTestMochaConfig {
9
+ recursive: boolean;
10
+ require: string[];
11
+ "unhandled-rejections": string;
12
+ "fail-zero": boolean;
13
+ ignore: string[];
14
+ "node-option": string[];
15
+ spec: string;
16
+ exit?: boolean;
17
+ timeout?: number | string;
18
+ fgrep?: string[];
19
+ reporter?: string;
20
+ reporterOptions?: string[];
21
+ "reporter-options"?: string[];
22
+ "forbid-only"?: boolean;
23
+ }
24
+ /**
25
+ * Get the mocha configuration for running tests using the conventions followed in the Fluid Framework repository.
26
+ *
27
+ * @param packageDir - the directory of the package, typically set using `__dirname`
28
+ * @param additionalRequiredModules - modules to require in addition to the standard set.
29
+ * @param testReportPrefix - prefix for the test output report file names.
30
+ * @remarks
31
+ * Additional configuration can be provided via environment variables: see {@link file://./README.md}.
32
+ *
33
+ * Users desiring exact control over the `spec` from the CLI should delete or replace the spec from the returned config, since mocha's behavior is to extend it, not override it.
34
+ */
35
+ export declare function getFluidTestMochaConfig(packageDir: string, additionalRequiredModules?: string[], testReportPrefix?: string): FluidTestMochaConfig;
36
+ //# sourceMappingURL=mocharcCommon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mocharcCommon.d.ts","sourceRoot":"","sources":["../src/mocharcCommon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACtC,UAAU,EAAE,MAAM,EAClB,yBAAyB,CAAC,EAAE,MAAM,EAAE,EACpC,gBAAgB,CAAC,EAAE,MAAM,GACvB,oBAAoB,CAyGtB"}
@@ -0,0 +1,106 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { readFileSync } from "node:fs";
6
+ import path from "node:path";
7
+ /**
8
+ * Get the mocha configuration for running tests using the conventions followed in the Fluid Framework repository.
9
+ *
10
+ * @param packageDir - the directory of the package, typically set using `__dirname`
11
+ * @param additionalRequiredModules - modules to require in addition to the standard set.
12
+ * @param testReportPrefix - prefix for the test output report file names.
13
+ * @remarks
14
+ * Additional configuration can be provided via environment variables: see {@link file://./README.md}.
15
+ *
16
+ * Users desiring exact control over the `spec` from the CLI should delete or replace the spec from the returned config, since mocha's behavior is to extend it, not override it.
17
+ */
18
+ export function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testReportPrefix) {
19
+ const requiredModules = [
20
+ // General mocha setup e.g. suppresses console.log,
21
+ // This has to be before others (except logger) so that registerMochaTestWrapperFuncs is available
22
+ "@fluid-internal/mocha-test-setup",
23
+ "source-map-support/register",
24
+ ...(additionalRequiredModules ?? []),
25
+ ];
26
+ if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER !== undefined) {
27
+ // Inject implementation of createTestLogger, put it first before mocha-test-setup
28
+ requiredModules.unshift(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);
29
+ }
30
+ let reportPrefix = testReportPrefix;
31
+ let defaultSpec = "lib/test";
32
+ if (process.env.FLUID_TEST_MODULE_SYSTEM === "CJS") {
33
+ defaultSpec = "dist/test";
34
+ const testVariant = process.env.FLUID_TEST_VARIANT;
35
+ process.env.FLUID_TEST_VARIANT = testVariant !== undefined ? `CJS,${testVariant}` : "CJS";
36
+ reportPrefix = reportPrefix !== undefined ? `${reportPrefix}-CJS` : "CJS";
37
+ }
38
+ const config = {
39
+ "recursive": true,
40
+ "require": requiredModules,
41
+ "unhandled-rejections": "strict",
42
+ // Fail the test run if no tests are found/run. This catches cases where test files fail to
43
+ // load silently (e.g. due to broken imports), which would otherwise produce a green "0 passing"
44
+ // result with exit code 0.
45
+ "fail-zero": true,
46
+ ignore: [
47
+ // Ignore "tools" which are scripts intended to be run, not part of the test suite.
48
+ "**/*.tool.{js,cjs,mjs}",
49
+ ],
50
+ "node-option": [
51
+ // Allow test-only indexes to be imported. Search the FF repo for package.json files with this condition to see example usage.
52
+ "conditions=allow-ff-test-exports",
53
+ // Performance tests benefit from having access to GC, and memory tests require it.
54
+ // Exposing it here avoids all packages which do perf testing from having to expose it.
55
+ // Note that since "node-option" is explicitly set,
56
+ // these must be provided here and not via mocha's --v8-expose-gc.
57
+ "expose-gc",
58
+ ],
59
+ spec: process.env.MOCHA_SPEC ?? defaultSpec,
60
+ };
61
+ // This approach to checking for this flag is consistent with some (but not all) others in this file,
62
+ // but not with tools/benchmark/src/Configuration.ts.
63
+ // For now, undefined, "1" and "true" should work consistently across all known use, and "1" is the main form we explicitly use.
64
+ // All these should be made to match, see AB#69054.
65
+ if (process.env.FLUID_TEST_PERF_MODE !== undefined) {
66
+ if (process.env.SILENT_TEST_OUTPUT === undefined) {
67
+ console.log(`Running performance tests...`);
68
+ }
69
+ // Some perf tests are often quite slow, and we don't want to lose the data by hitting a timeout.
70
+ // This is 1000 seconds, so ~16 minutes.
71
+ // This can be overridden by setting FLUID_TEST_TIMEOUT to a different value if desired.
72
+ config.timeout = 1_000_000;
73
+ // If there is no filter specified, limit to benchmarks.
74
+ // If mocha allowed multiple filters to all be applied to further narrow results, we would do this unconditionally.
75
+ if (!(process.argv.includes("--fgrep") || process.argv.includes("--grep"))) {
76
+ config.fgrep = ["@Benchmark"];
77
+ }
78
+ config.reporter = "@fluid-tools/benchmark/dist/mocha/Reporter.js";
79
+ if (!process.argv.includes("--reporterOptions")) {
80
+ // If report options were not specified, default to:
81
+ config.reporterOptions = ["reportFile=./benchmarkOutput.json"];
82
+ }
83
+ }
84
+ else {
85
+ const packageJsonPath = path.join(packageDir, "package.json");
86
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
87
+ config.reporter = `mocha-multi-reporters`;
88
+ // See https://www.npmjs.com/package/mocha-multi-reporters#cmroutput-option
89
+ const outputFilePrefix = reportPrefix !== undefined ? `${reportPrefix}-` : "";
90
+ if (process.env.SILENT_TEST_OUTPUT === undefined) {
91
+ console.log(`Writing test results relative to package to nyc/${outputFilePrefix}junit-report.xml`);
92
+ }
93
+ const suiteName = reportPrefix !== undefined ? `${packageJson.name} - ${reportPrefix}` : packageJson.name;
94
+ config["reporter-options"] = [
95
+ `configFile=${path.join(import.meta.dirname, "..", "test-config.json")},cmrOutput=xunit+output+${outputFilePrefix}:xunit+suiteName+${suiteName}`,
96
+ ];
97
+ }
98
+ if (process.env.FLUID_TEST_TIMEOUT !== undefined) {
99
+ config.timeout = process.env.FLUID_TEST_TIMEOUT;
100
+ }
101
+ if (process.env.FLUID_TEST_FORBID_ONLY !== undefined) {
102
+ config["forbid-only"] = true;
103
+ }
104
+ return config;
105
+ }
106
+ //# sourceMappingURL=mocharcCommon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mocharcCommon.js","sourceRoot":"","sources":["../src/mocharcCommon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAsB7B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CACtC,UAAkB,EAClB,yBAAoC,EACpC,gBAAyB;IAEzB,MAAM,eAAe,GAAG;QACvB,mDAAmD;QACnD,kGAAkG;QAClG,kCAAkC;QAClC,6BAA6B;QAC7B,GAAG,CAAC,yBAAyB,IAAI,EAAE,CAAC;KACpC,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,+BAA+B,KAAK,SAAS,EAAE,CAAC;QAC/D,kFAAkF;QAClF,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,YAAY,GAAG,gBAAgB,CAAC;IACpC,IAAI,WAAW,GAAG,UAAU,CAAC;IAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,KAAK,EAAE,CAAC;QACpD,WAAW,GAAG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AClD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,SAAS,EAAE,CAAC;QACtD,MAAM,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Mocha configuration object returned by {@link getFluidTestMochaConfig}.\n */\nexport interface FluidTestMochaConfig {\n\trecursive: boolean;\n\trequire: string[];\n\t\"unhandled-rejections\": string;\n\t\"fail-zero\": boolean;\n\tignore: string[];\n\t\"node-option\": string[];\n\tspec: string;\n\texit?: boolean;\n\ttimeout?: number | string;\n\tfgrep?: string[];\n\treporter?: string;\n\treporterOptions?: string[];\n\t\"reporter-options\"?: string[];\n\t\"forbid-only\"?: boolean;\n}\n\n/**\n * Get the mocha configuration for running tests using the conventions followed in the Fluid Framework repository.\n *\n * @param packageDir - the directory of the package, typically set using `__dirname`\n * @param additionalRequiredModules - modules to require in addition to the standard set.\n * @param testReportPrefix - prefix for the test output report file names.\n * @remarks\n * Additional configuration can be provided via environment variables: see {@link file://./README.md}.\n *\n * Users desiring exact control over the `spec` from the CLI should delete or replace the spec from the returned config, since mocha's behavior is to extend it, not override it.\n */\nexport function getFluidTestMochaConfig(\n\tpackageDir: string,\n\tadditionalRequiredModules?: string[],\n\ttestReportPrefix?: string,\n): FluidTestMochaConfig {\n\tconst requiredModules = [\n\t\t// General mocha setup e.g. suppresses console.log,\n\t\t// This has to be before others (except logger) so that registerMochaTestWrapperFuncs is available\n\t\t\"@fluid-internal/mocha-test-setup\",\n\t\t\"source-map-support/register\",\n\t\t...(additionalRequiredModules ?? []),\n\t];\n\n\tif (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER !== undefined) {\n\t\t// Inject implementation of createTestLogger, put it first before mocha-test-setup\n\t\trequiredModules.unshift(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);\n\t}\n\n\tlet reportPrefix = testReportPrefix;\n\tlet defaultSpec = \"lib/test\";\n\tif (process.env.FLUID_TEST_MODULE_SYSTEM === \"CJS\") {\n\t\tdefaultSpec = \"dist/test\";\n\t\tconst testVariant = process.env.FLUID_TEST_VARIANT;\n\t\tprocess.env.FLUID_TEST_VARIANT = testVariant !== undefined ? `CJS,${testVariant}` : \"CJS\";\n\t\treportPrefix = reportPrefix !== undefined ? `${reportPrefix}-CJS` : \"CJS\";\n\t}\n\n\tconst config: FluidTestMochaConfig = {\n\t\t\"recursive\": true,\n\t\t\"require\": requiredModules,\n\t\t\"unhandled-rejections\": \"strict\",\n\t\t// Fail the test run if no tests are found/run. This catches cases where test files fail to\n\t\t// load silently (e.g. due to broken imports), which would otherwise produce a green \"0 passing\"\n\t\t// result with exit code 0.\n\t\t\"fail-zero\": true,\n\t\tignore: [\n\t\t\t// Ignore \"tools\" which are scripts intended to be run, not part of the test suite.\n\t\t\t\"**/*.tool.{js,cjs,mjs}\",\n\t\t],\n\t\t\"node-option\": [\n\t\t\t// Allow test-only indexes to be imported. Search the FF repo for package.json files with this condition to see example usage.\n\t\t\t\"conditions=allow-ff-test-exports\",\n\t\t\t// Performance tests benefit from having access to GC, and memory tests require it.\n\t\t\t// Exposing it here avoids all packages which do perf testing from having to expose it.\n\t\t\t// Note that since \"node-option\" is explicitly set,\n\t\t\t// these must be provided here and not via mocha's --v8-expose-gc.\n\t\t\t\"expose-gc\",\n\t\t],\n\t\tspec: process.env.MOCHA_SPEC ?? defaultSpec,\n\t};\n\n\t// This approach to checking for this flag is consistent with some (but not all) others in this file,\n\t// but not with tools/benchmark/src/Configuration.ts.\n\t// For now, undefined, \"1\" and \"true\" should work consistently across all known use, and \"1\" is the main form we explicitly use.\n\t// All these should be made to match, see AB#69054.\n\tif (process.env.FLUID_TEST_PERF_MODE !== undefined) {\n\t\tif (process.env.SILENT_TEST_OUTPUT === undefined) {\n\t\t\tconsole.log(`Running performance tests...`);\n\t\t}\n\n\t\t// Some perf tests are often quite slow, and we don't want to lose the data by hitting a timeout.\n\t\t// This is 1000 seconds, so ~16 minutes.\n\t\t// This can be overridden by setting FLUID_TEST_TIMEOUT to a different value if desired.\n\t\tconfig.timeout = 1_000_000;\n\n\t\t// If there is no filter specified, limit to benchmarks.\n\t\t// If mocha allowed multiple filters to all be applied to further narrow results, we would do this unconditionally.\n\t\tif (!(process.argv.includes(\"--fgrep\") || process.argv.includes(\"--grep\"))) {\n\t\t\tconfig.fgrep = [\"@Benchmark\"];\n\t\t}\n\n\t\tconfig.reporter = \"@fluid-tools/benchmark/dist/mocha/Reporter.js\";\n\t\tif (!process.argv.includes(\"--reporterOptions\")) {\n\t\t\t// If report options were not specified, default to:\n\t\t\tconfig.reporterOptions = [\"reportFile=./benchmarkOutput.json\"];\n\t\t}\n\t} else {\n\t\tconst packageJsonPath = path.join(packageDir, \"package.json\");\n\t\tconst packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as {\n\t\t\tname: string;\n\t\t};\n\t\tconfig.reporter = `mocha-multi-reporters`;\n\t\t// See https://www.npmjs.com/package/mocha-multi-reporters#cmroutput-option\n\t\tconst outputFilePrefix = reportPrefix !== undefined ? `${reportPrefix}-` : \"\";\n\t\tif (process.env.SILENT_TEST_OUTPUT === undefined) {\n\t\t\tconsole.log(\n\t\t\t\t`Writing test results relative to package to nyc/${outputFilePrefix}junit-report.xml`,\n\t\t\t);\n\t\t}\n\t\tconst suiteName =\n\t\t\treportPrefix !== undefined ? `${packageJson.name} - ${reportPrefix}` : packageJson.name;\n\t\tconfig[\"reporter-options\"] = [\n\t\t\t`configFile=${path.join(\n\t\t\t\timport.meta.dirname,\n\t\t\t\t\"..\",\n\t\t\t\t\"test-config.json\",\n\t\t\t)},cmrOutput=xunit+output+${outputFilePrefix}:xunit+suiteName+${suiteName}`,\n\t\t];\n\t}\n\n\tif (process.env.FLUID_TEST_TIMEOUT !== undefined) {\n\t\tconfig.timeout = process.env.FLUID_TEST_TIMEOUT;\n\t}\n\n\tif (process.env.FLUID_TEST_FORBID_ONLY !== undefined) {\n\t\tconfig[\"forbid-only\"] = true;\n\t}\n\n\treturn config;\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluid-internal/mocha-test-setup";
8
- export declare const pkgVersion = "2.101.1";
8
+ export declare const pkgVersion = "2.103.0";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluid-internal/mocha-test-setup";
8
- export const pkgVersion = "2.101.1";
8
+ export const pkgVersion = "2.103.0";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAC1D,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-internal/mocha-test-setup\";\nexport const pkgVersion = \"2.101.1\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAC1D,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-internal/mocha-test-setup\";\nexport const pkgVersion = \"2.103.0\";\n"]}
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ // This file exists to preserve CommonJS default export compatibility for the mocharc-common entrypoint.
7
+ // Once all consumers are using named imports, this file can be removed and all conditions can point
8
+ // directly to the ESM file. attw mocharc-common exclusion can also be removed at that time.
9
+
10
+ "use strict";
11
+
12
+ const { getFluidTestMochaConfig } = require("./lib/mocharcCommon.js");
13
+
14
+ module.exports = getFluidTestMochaConfig;
15
+ module.exports.getFluidTestMochaConfig = getFluidTestMochaConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-internal/mocha-test-setup",
3
- "version": "2.101.1",
3
+ "version": "2.103.0",
4
4
  "description": "Utilities for Fluid tests",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -14,24 +14,16 @@
14
14
  "type": "module",
15
15
  "exports": {
16
16
  ".": {
17
- "import": {
18
- "types": "./lib/index.d.ts",
19
- "default": "./lib/index.js"
20
- },
21
- "require": {
22
- "types": "./dist/index.d.ts",
23
- "default": "./dist/index.js"
24
- }
17
+ "default": "./lib/index.js"
25
18
  },
26
19
  "./mocharc-common": {
27
- "require": "./mocharc-common.cjs"
20
+ "require": "./mocharc-common-cjswrapper.cjs",
21
+ "default": "./lib/mocharcCommon.js"
28
22
  }
29
23
  },
30
- "main": "dist/index.js",
31
- "types": "dist/index.d.ts",
32
24
  "dependencies": {
33
- "@fluid-internal/test-driver-definitions": "~2.101.1",
34
- "@fluidframework/core-interfaces": "~2.101.1",
25
+ "@fluid-internal/test-driver-definitions": "~2.103.0",
26
+ "@fluidframework/core-interfaces": "~2.103.0",
35
27
  "mocha": "^11.7.5",
36
28
  "source-map-support": "^0.5.21"
37
29
  },
@@ -52,6 +44,17 @@
52
44
  "rimraf": "^6.1.3",
53
45
  "typescript": "~5.4.5"
54
46
  },
47
+ "fluidBuild": {
48
+ "_tasks_comment": "tsc is configured to depend on build:esnext task as all CommonJS consumers expect mocha support which is implemented in ESM. Building ESM when CommonJS is requested ensures the implementation expectation is satisfied.",
49
+ "tasks": {
50
+ "tsc": {
51
+ "dependsOn": [
52
+ "build:esnext"
53
+ ],
54
+ "script": false
55
+ }
56
+ }
57
+ },
55
58
  "typeValidation": {
56
59
  "disabled": true
57
60
  },
@@ -63,11 +66,10 @@
63
66
  "build:docs": "api-extractor run --local",
64
67
  "build:esnext": "tsc --project ./tsconfig.json",
65
68
  "build:genver": "gen-version",
66
- "check:are-the-types-wrong": "attw --pack . --exclude-entrypoints ./mocharc-common",
69
+ "check:are-the-types-wrong": "attw --pack . --profile node16 --exclude-entrypoints ./mocharc-common",
67
70
  "check:biome": "biome check .",
68
71
  "check:exports": "concurrently \"npm:check:exports:*\"",
69
72
  "check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
70
- "check:exports:cjs:index": "api-extractor run --config api-extractor/api-extractor-lint-index.cjs.json",
71
73
  "check:exports:esm:index": "api-extractor run --config api-extractor/api-extractor-lint-index.esm.json",
72
74
  "check:format": "npm run check:biome",
73
75
  "ci:build:docs": "api-extractor run",
@@ -77,7 +79,6 @@
77
79
  "format": "npm run format:biome",
78
80
  "format:biome": "biome check . --write",
79
81
  "lint": "fluid-build . --task lint",
80
- "lint:fix": "fluid-build . --task eslint:fix --task format",
81
- "tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist"
82
+ "lint:fix": "fluid-build . --task eslint:fix --task format"
82
83
  }
83
84
  }
@@ -3,44 +3,68 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- "use strict";
6
+ import { readFileSync } from "node:fs";
7
+ import path from "node:path";
7
8
 
8
- const path = require("path");
9
+ /**
10
+ * Mocha configuration object returned by {@link getFluidTestMochaConfig}.
11
+ */
12
+ export interface FluidTestMochaConfig {
13
+ recursive: boolean;
14
+ require: string[];
15
+ "unhandled-rejections": string;
16
+ "fail-zero": boolean;
17
+ ignore: string[];
18
+ "node-option": string[];
19
+ spec: string;
20
+ exit?: boolean;
21
+ timeout?: number | string;
22
+ fgrep?: string[];
23
+ reporter?: string;
24
+ reporterOptions?: string[];
25
+ "reporter-options"?: string[];
26
+ "forbid-only"?: boolean;
27
+ }
9
28
 
10
29
  /**
11
30
  * Get the mocha configuration for running tests using the conventions followed in the Fluid Framework repository.
12
31
  *
13
- * @param {string} packageDir - the directory of the package, typically set using `__dirname`
14
- * @param {string[]} additionalRequiredModules - modules to require in addition to the standard set.
15
- * @param {string} testReportPrefix - prefix for the test output report file names.
32
+ * @param packageDir - the directory of the package, typically set using `__dirname`
33
+ * @param additionalRequiredModules - modules to require in addition to the standard set.
34
+ * @param testReportPrefix - prefix for the test output report file names.
16
35
  * @remarks
17
36
  * Additional configuration can be provided via environment variables: see {@link file://./README.md}.
18
37
  *
19
38
  * Users desiring exact control over the `spec` from the CLI should delete or replace the spec from the returned config, since mocha's behavior is to extend it, not override it.
20
39
  */
21
- function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testReportPrefix) {
40
+ export function getFluidTestMochaConfig(
41
+ packageDir: string,
42
+ additionalRequiredModules?: string[],
43
+ testReportPrefix?: string,
44
+ ): FluidTestMochaConfig {
22
45
  const requiredModules = [
23
46
  // General mocha setup e.g. suppresses console.log,
24
47
  // This has to be before others (except logger) so that registerMochaTestWrapperFuncs is available
25
48
  "@fluid-internal/mocha-test-setup",
26
49
  "source-map-support/register",
27
- ...(additionalRequiredModules ? additionalRequiredModules : []),
50
+ ...(additionalRequiredModules ?? []),
28
51
  ];
29
52
 
30
- if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER) {
53
+ if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER !== undefined) {
31
54
  // Inject implementation of createTestLogger, put it first before mocha-test-setup
32
55
  requiredModules.unshift(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);
33
56
  }
34
57
 
58
+ let reportPrefix = testReportPrefix;
35
59
  let defaultSpec = "lib/test";
36
60
  if (process.env.FLUID_TEST_MODULE_SYSTEM === "CJS") {
37
61
  defaultSpec = "dist/test";
38
62
  const testVariant = process.env.FLUID_TEST_VARIANT;
39
63
  process.env.FLUID_TEST_VARIANT = testVariant !== undefined ? `CJS,${testVariant}` : "CJS";
40
- testReportPrefix = testReportPrefix !== undefined ? `${testReportPrefix}-CJS` : "CJS";
64
+ reportPrefix = reportPrefix !== undefined ? `${reportPrefix}-CJS` : "CJS";
41
65
  }
42
66
 
43
- const config = {
67
+ const config: FluidTestMochaConfig = {
44
68
  "recursive": true,
45
69
  "require": requiredModules,
46
70
  "unhandled-rejections": "strict",
@@ -69,50 +93,52 @@ function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testRepo
69
93
  // For now, undefined, "1" and "true" should work consistently across all known use, and "1" is the main form we explicitly use.
70
94
  // All these should be made to match, see AB#69054.
71
95
  if (process.env.FLUID_TEST_PERF_MODE !== undefined) {
72
- if (!process.env.SILENT_TEST_OUTPUT) {
96
+ if (process.env.SILENT_TEST_OUTPUT === undefined) {
73
97
  console.log(`Running performance tests...`);
74
98
  }
75
99
 
76
100
  // Some perf tests are often quite slow, and we don't want to lose the data by hitting a timeout.
77
101
  // This is 1000 seconds, so ~16 minutes.
78
102
  // This can be overridden by setting FLUID_TEST_TIMEOUT to a different value if desired.
79
- config["timeout"] = 1_000_000;
103
+ config.timeout = 1_000_000;
80
104
 
81
105
  // If there is no filter specified, limit to benchmarks.
82
106
  // If mocha allowed multiple filters to all be applied to further narrow results, we would do this unconditionally.
83
107
  if (!(process.argv.includes("--fgrep") || process.argv.includes("--grep"))) {
84
- config["fgrep"] = ["@Benchmark"];
108
+ config.fgrep = ["@Benchmark"];
85
109
  }
86
110
 
87
- config["reporter"] = "@fluid-tools/benchmark/dist/mocha/Reporter.js";
111
+ config.reporter = "@fluid-tools/benchmark/dist/mocha/Reporter.js";
88
112
  if (!process.argv.includes("--reporterOptions")) {
89
113
  // If report options were not specified, default to:
90
- config["reporterOptions"] = ["reportFile=./benchmarkOutput.json"];
114
+ config.reporterOptions = ["reportFile=./benchmarkOutput.json"];
91
115
  }
92
116
  } else {
93
- const packageJson = require(`${packageDir}/package.json`);
94
- config["reporter"] = `mocha-multi-reporters`;
117
+ const packageJsonPath = path.join(packageDir, "package.json");
118
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as {
119
+ name: string;
120
+ };
121
+ config.reporter = `mocha-multi-reporters`;
95
122
  // See https://www.npmjs.com/package/mocha-multi-reporters#cmroutput-option
96
- const outputFilePrefix = testReportPrefix !== undefined ? `${testReportPrefix}-` : "";
97
- if (!process.env.SILENT_TEST_OUTPUT) {
123
+ const outputFilePrefix = reportPrefix !== undefined ? `${reportPrefix}-` : "";
124
+ if (process.env.SILENT_TEST_OUTPUT === undefined) {
98
125
  console.log(
99
126
  `Writing test results relative to package to nyc/${outputFilePrefix}junit-report.xml`,
100
127
  );
101
128
  }
102
129
  const suiteName =
103
- testReportPrefix !== undefined
104
- ? `${packageJson.name} - ${testReportPrefix}`
105
- : packageJson.name;
130
+ reportPrefix !== undefined ? `${packageJson.name} - ${reportPrefix}` : packageJson.name;
106
131
  config["reporter-options"] = [
107
132
  `configFile=${path.join(
108
- __dirname,
133
+ import.meta.dirname,
134
+ "..",
109
135
  "test-config.json",
110
136
  )},cmrOutput=xunit+output+${outputFilePrefix}:xunit+suiteName+${suiteName}`,
111
137
  ];
112
138
  }
113
139
 
114
140
  if (process.env.FLUID_TEST_TIMEOUT !== undefined) {
115
- config["timeout"] = process.env.FLUID_TEST_TIMEOUT;
141
+ config.timeout = process.env.FLUID_TEST_TIMEOUT;
116
142
  }
117
143
 
118
144
  if (process.env.FLUID_TEST_FORBID_ONLY !== undefined) {
@@ -121,5 +147,3 @@ function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testRepo
121
147
 
122
148
  return config;
123
149
  }
124
-
125
- module.exports = getFluidTestMochaConfig;
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluid-internal/mocha-test-setup";
9
- export const pkgVersion = "2.101.1";
9
+ export const pkgVersion = "2.103.0";
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export { mochaHooks } from "./mochaHooks.js";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.mochaHooks = void 0;
8
- var mochaHooks_js_1 = require("./mochaHooks.js");
9
- Object.defineProperty(exports, "mochaHooks", { enumerable: true, get: function () { return mochaHooks_js_1.mochaHooks; } });
10
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAA6C;AAApC,2GAAA,UAAU,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { mochaHooks } from \"./mochaHooks.js\";\n"]}
@@ -1,15 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- /// <reference types="mocha" />
6
- /**
7
- * @internal
8
- */
9
- export declare const mochaHooks: {
10
- beforeAll(): Promise<void>;
11
- beforeEach(this: Mocha.Context): void;
12
- afterEach(this: Mocha.Context): void;
13
- afterAll(this: Mocha.Context): Promise<void>;
14
- };
15
- //# sourceMappingURL=mochaHooks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mochaHooks.d.ts","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AA0FH;;GAEG;AACH,eAAO,MAAM,UAAU;;qBAkCL,MAAM,OAAO;oBAwBd,MAAM,OAAO;mBAqBR,MAAM,OAAO;CAMlC,CAAC"}
@@ -1,193 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || function (mod) {
23
- if (mod && mod.__esModule) return mod;
24
- var result = {};
25
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
- __setModuleDefault(result, mod);
27
- return result;
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.mochaHooks = void 0;
31
- const mochaModule = __importStar(require("mocha"));
32
- const packageVersion_js_1 = require("./packageVersion.js");
33
- // This will enable capturing the full stack for errors.
34
- // Since this package is only used when we run tests, capturing the full stack is worth it.
35
- // In non-test environments we need to be more cautious as this will incur a perf impact when errors are
36
- // thrown and will take more storage in any logging sink.
37
- // https://v8.dev/docs/stack-trace-api
38
- Error.stackTraceLimit = Number.POSITIVE_INFINITY;
39
- const testVariant = process.env.FLUID_TEST_VARIANT;
40
- const envLoggerProps = process.env.FLUID_LOGGER_PROPS != null
41
- ? JSON.parse(process.env.FLUID_LOGGER_PROPS)
42
- : undefined;
43
- const _global = global;
44
- /**
45
- * A logger that adds context about the current test run to all events logged through it, like the test variant being
46
- * run (odsp, r11s, etc) and the name of the current test (while in the context of a particular test running).
47
- */
48
- class FluidTestRunLogger {
49
- send(event) {
50
- // TODO: Remove when issue #7061 is resolved.
51
- // Don't log this event as we generate too much.
52
- if (event.eventName === "fluid:telemetry:RouterliciousDriver:readBlob_end") {
53
- return;
54
- }
55
- if (this.currentTestName !== undefined) {
56
- event.testName = this.currentTestName;
57
- }
58
- event.testVariant = testVariant;
59
- this.parentLogger.send({
60
- ...event,
61
- // Setting hostname to pkgName is the behavior we had for a long time, so keeping it just in case.
62
- // But prefer a value set through FLUID_LOGGER_PROPS if it exists.
63
- hostName: envLoggerProps?.hostName ?? packageVersion_js_1.pkgName,
64
- testEnvProps: JSON.stringify(envLoggerProps),
65
- });
66
- }
67
- async flush() {
68
- return this.parentLogger.flush();
69
- }
70
- constructor(parentLogger) {
71
- this.parentLogger = parentLogger;
72
- }
73
- /**
74
- * Sets the test that is currently running.
75
- * The test name will be included in all events logged through the logger until {@link clearCurrentTest} is called.
76
- * @param testName - The name of the test that is currently running.
77
- */
78
- setCurrentTest(testName) {
79
- this.currentTestName = testName;
80
- }
81
- /**
82
- * Clears the test that is currently running.
83
- * Must be called after a given test has completed so that events logged outside the context of a test
84
- * don't include the name of the last test that ran.
85
- */
86
- clearCurrentTest() {
87
- this.currentTestName = undefined;
88
- }
89
- }
90
- const nullLogger = {
91
- send: () => { },
92
- flush: async () => { },
93
- };
94
- // Keep references to the original console functions so we can restore them after each test.
95
- const log = console.log;
96
- const error = console.log;
97
- const warn = console.warn;
98
- let testLogger;
99
- /**
100
- * The amount of time to wait after logging an event before flushing the logger.
101
- * This amount was decided after doing tests with different values. See AB#44378 for details.
102
- */
103
- const AFTER_FLUSH_DELAY_MS = 1250;
104
- /**
105
- * @internal
106
- */
107
- exports.mochaHooks = {
108
- async beforeAll() {
109
- // Code in our tests will call the global `getTestLogger` function to get a logger to use.
110
- // First we call the version of that function that was (potentially) injected dynamicaly to get the logger that it
111
- // provides and wrap it with a more intelligent logger which adds test-run-related context to all events logged
112
- // through it. See the documentation on `FluidTestRunLogger` for details.
113
- let originalLogger;
114
- if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER === undefined) {
115
- originalLogger = nullLogger;
116
- }
117
- else {
118
- const { createTestLogger } = await import(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);
119
- if (typeof createTestLogger !== "function") {
120
- throw new TypeError(`Expected package '${process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER}' to export a function, but got an object of type '${typeof createTestLogger}' instead`);
121
- }
122
- else {
123
- originalLogger = createTestLogger({
124
- afterFlushDelayMs: AFTER_FLUSH_DELAY_MS,
125
- throttleLogging: false,
126
- });
127
- }
128
- }
129
- testLogger = new FluidTestRunLogger(originalLogger);
130
- // Then we redefine `getTestLogger` so it returns the wrapper logger.
131
- // NOTE: if we have other global mocha hooks defined somewhere, they include a `beforeEach` hook, and the module in
132
- // which they are defined gets loaded before this one, then if that `beforeEach` hook calls `getTestLogger` the logger
133
- // it will get will still have a lot of the test-run-related context, but not the name of the current test, because
134
- // it will run before the `beforeEach` hook in this file which sets that.
135
- _global.getTestLogger = () => testLogger;
136
- },
137
- beforeEach() {
138
- // If not in verbose mode, suppress console output while the current test runs.
139
- if (process.env.FLUID_TEST_VERBOSE === undefined) {
140
- console.log = () => { };
141
- console.error = () => { };
142
- console.warn = () => { };
143
- }
144
- ensureTestRunLoggerIsInitialized(testLogger);
145
- let testTitle = "";
146
- if (this.currentTest !== undefined) {
147
- if (testVariant !== undefined) {
148
- this.currentTest.title = `[${testVariant}] ${this.currentTest.title}`;
149
- }
150
- testTitle = this.currentTest.fullTitle();
151
- }
152
- testLogger.setCurrentTest(testTitle);
153
- testLogger.send({
154
- category: "generic",
155
- eventName: "fluid:telemetry:Test_start",
156
- });
157
- },
158
- afterEach() {
159
- ensureTestRunLoggerIsInitialized(testLogger);
160
- testLogger.send({
161
- category: "generic",
162
- eventName: "fluid:telemetry:Test_end",
163
- state: this.currentTest?.state,
164
- duration: this.currentTest?.duration,
165
- timedOut: this.currentTest?.timedOut,
166
- error: this.currentTest?.err?.message,
167
- stack: this.currentTest?.err?.stack,
168
- });
169
- // Restore console output now that the current test is done running.
170
- console.log = log;
171
- console.error = error;
172
- console.warn = warn;
173
- // Clear the current test from the logger. Important so if anything calls `getTestLogger` outside the context of a
174
- // test (e.g. during a `before` or `after` hook), it doesn't log events with the name of the last test that ran.
175
- testLogger.clearCurrentTest();
176
- },
177
- async afterAll() {
178
- // Allow 5 seconds for the logger to flush.
179
- this.timeout(5000);
180
- // After all tests ran, flush the logger to ensure all events are sent before the process exits.
181
- await testLogger.flush();
182
- },
183
- };
184
- globalThis.getMochaModule = () => {
185
- return mochaModule;
186
- };
187
- function ensureTestRunLoggerIsInitialized(loggerToTest) {
188
- if (loggerToTest instanceof FluidTestRunLogger) {
189
- return true;
190
- }
191
- throw new Error("Test run logger is not initialized");
192
- }
193
- //# sourceMappingURL=mochaHooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mochaHooks.js","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAIH,mDAAqC;AAErC,2DAA8C;AAE9C,wDAAwD;AACxD,2FA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,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK;SACnC,CAAC,CAAC;QAEH,oEAAoE;QACpE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;QAClB,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACtB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QAEpB,kHAAkH;QAClH,gHAAgH;QAChH,UAAU,CAAC,gBAAgB,EAAE,CAAC;IAC/B,CAAC;IACD,KAAK,CAAC,QAAQ;QACb,2CAA2C;QAC3C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnB,gGAAgG;QAChG,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACD,CAAC;AAEF,UAAU,CAAC,cAAc,GAAG,GAAG,EAAE;IAChC,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC;AAEF,SAAS,gCAAgC,CACxC,YAA4C;IAE5C,IAAI,YAAY,YAAY,kBAAkB,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACvD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBufferedLogger } from \"@fluid-internal/test-driver-definitions\";\nimport type { ITelemetryBaseEvent } from \"@fluidframework/core-interfaces\";\nimport * as mochaModule from \"mocha\";\n\nimport { pkgName } from \"./packageVersion.js\";\n\n// This will enable capturing the full stack for errors.\n// Since this package is only used when we run tests, capturing the full stack is worth it.\n// In non-test environments we need to be more cautious as this will incur a perf impact when errors are\n// thrown and will take more storage in any logging sink.\n// https://v8.dev/docs/stack-trace-api\nError.stackTraceLimit = Number.POSITIVE_INFINITY;\n\nconst testVariant = process.env.FLUID_TEST_VARIANT;\nconst envLoggerProps =\n\tprocess.env.FLUID_LOGGER_PROPS != null\n\t\t? JSON.parse(process.env.FLUID_LOGGER_PROPS)\n\t\t: undefined;\n\nconst _global: any = global;\n\n/**\n * A logger that adds context about the current test run to all events logged through it, like the test variant being\n * run (odsp, r11s, etc) and the name of the current test (while in the context of a particular test running).\n */\nclass FluidTestRunLogger implements ITelemetryBufferedLogger {\n\tprivate currentTestName: string | undefined;\n\n\tsend(event: ITelemetryBaseEvent): void {\n\t\t// TODO: Remove when issue #7061 is resolved.\n\t\t// Don't log this event as we generate too much.\n\t\tif (event.eventName === \"fluid:telemetry:RouterliciousDriver:readBlob_end\") {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.currentTestName !== undefined) {\n\t\t\tevent.testName = this.currentTestName;\n\t\t}\n\t\tevent.testVariant = testVariant;\n\t\tthis.parentLogger.send({\n\t\t\t...event,\n\t\t\t// Setting hostname to pkgName is the behavior we had for a long time, so keeping it just in case.\n\t\t\t// But prefer a value set through FLUID_LOGGER_PROPS if it exists.\n\t\t\thostName: envLoggerProps?.hostName ?? pkgName,\n\t\t\ttestEnvProps: JSON.stringify(envLoggerProps),\n\t\t});\n\t}\n\tasync flush(): Promise<void> {\n\t\treturn this.parentLogger.flush();\n\t}\n\tconstructor(private readonly parentLogger: ITelemetryBufferedLogger) {}\n\n\t/**\n\t * Sets the test that is currently running.\n\t * The test name will be included in all events logged through the logger until {@link clearCurrentTest} is called.\n\t * @param testName - The name of the test that is currently running.\n\t */\n\tpublic setCurrentTest(testName: string): void {\n\t\tthis.currentTestName = testName;\n\t}\n\n\t/**\n\t * Clears the test that is currently running.\n\t * Must be called after a given test has completed so that events logged outside the context of a test\n\t * don't include the name of the last test that ran.\n\t */\n\tpublic clearCurrentTest(): void {\n\t\tthis.currentTestName = undefined;\n\t}\n}\nconst nullLogger: ITelemetryBufferedLogger = {\n\tsend: (): void => {},\n\tflush: async (): Promise<void> => {},\n};\n\n// Keep references to the original console functions so we can restore them after each test.\nconst log = console.log;\nconst error = console.log;\nconst warn = console.warn;\n\nlet testLogger: FluidTestRunLogger;\n\n/**\n * The amount of time to wait after logging an event before flushing the logger.\n * This amount was decided after doing tests with different values. See AB#44378 for details.\n */\nconst AFTER_FLUSH_DELAY_MS = 1250;\n\n/**\n * @internal\n */\nexport const mochaHooks = {\n\tasync beforeAll() {\n\t\t// Code in our tests will call the global `getTestLogger` function to get a logger to use.\n\n\t\t// First we call the version of that function that was (potentially) injected dynamicaly to get the logger that it\n\t\t// provides and wrap it with a more intelligent logger which adds test-run-related context to all events logged\n\t\t// through it. See the documentation on `FluidTestRunLogger` for details.\n\t\tlet originalLogger: ITelemetryBufferedLogger;\n\n\t\tif (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER === undefined) {\n\t\t\toriginalLogger = nullLogger;\n\t\t} else {\n\t\t\tconst { createTestLogger } = await import(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);\n\t\t\tif (typeof createTestLogger !== \"function\") {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Expected package '${process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER}' to export a function, but got an object of type '${typeof createTestLogger}' instead`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\toriginalLogger = createTestLogger({\n\t\t\t\t\tafterFlushDelayMs: AFTER_FLUSH_DELAY_MS,\n\t\t\t\t\tthrottleLogging: false,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\ttestLogger = new FluidTestRunLogger(originalLogger);\n\n\t\t// Then we redefine `getTestLogger` so it returns the wrapper logger.\n\t\t// NOTE: if we have other global mocha hooks defined somewhere, they include a `beforeEach` hook, and the module in\n\t\t// which they are defined gets loaded before this one, then if that `beforeEach` hook calls `getTestLogger` the logger\n\t\t// it will get will still have a lot of the test-run-related context, but not the name of the current test, because\n\t\t// it will run before the `beforeEach` hook in this file which sets that.\n\t\t_global.getTestLogger = () => testLogger;\n\t},\n\tbeforeEach(this: Mocha.Context) {\n\t\t// If not in verbose mode, suppress console output while the current test runs.\n\t\tif (process.env.FLUID_TEST_VERBOSE === undefined) {\n\t\t\tconsole.log = () => {};\n\t\t\tconsole.error = () => {};\n\t\t\tconsole.warn = () => {};\n\t\t}\n\n\t\tensureTestRunLoggerIsInitialized(testLogger);\n\n\t\tlet testTitle = \"\";\n\t\tif (this.currentTest !== undefined) {\n\t\t\tif (testVariant !== undefined) {\n\t\t\t\tthis.currentTest.title = `[${testVariant}] ${this.currentTest.title}`;\n\t\t\t}\n\t\t\ttestTitle = this.currentTest.fullTitle();\n\t\t}\n\t\ttestLogger.setCurrentTest(testTitle);\n\n\t\ttestLogger.send({\n\t\t\tcategory: \"generic\",\n\t\t\teventName: \"fluid:telemetry:Test_start\",\n\t\t});\n\t},\n\tafterEach(this: Mocha.Context) {\n\t\tensureTestRunLoggerIsInitialized(testLogger);\n\t\ttestLogger.send({\n\t\t\tcategory: \"generic\",\n\t\t\teventName: \"fluid:telemetry:Test_end\",\n\t\t\tstate: this.currentTest?.state,\n\t\t\tduration: this.currentTest?.duration,\n\t\t\ttimedOut: this.currentTest?.timedOut,\n\t\t\terror: this.currentTest?.err?.message,\n\t\t\tstack: this.currentTest?.err?.stack,\n\t\t});\n\n\t\t// Restore console output now that the current test is done running.\n\t\tconsole.log = log;\n\t\tconsole.error = error;\n\t\tconsole.warn = warn;\n\n\t\t// Clear the current test from the logger. Important so if anything calls `getTestLogger` outside the context of a\n\t\t// test (e.g. during a `before` or `after` hook), it doesn't log events with the name of the last test that ran.\n\t\ttestLogger.clearCurrentTest();\n\t},\n\tasync afterAll(this: Mocha.Context) {\n\t\t// Allow 5 seconds for the logger to flush.\n\t\tthis.timeout(5000);\n\t\t// After all tests ran, flush the logger to ensure all events are sent before the process exits.\n\t\tawait testLogger.flush();\n\t},\n};\n\nglobalThis.getMochaModule = () => {\n\treturn mochaModule;\n};\n\nfunction ensureTestRunLoggerIsInitialized(\n\tloggerToTest: FluidTestRunLogger | undefined,\n): loggerToTest is FluidTestRunLogger {\n\tif (loggerToTest instanceof FluidTestRunLogger) {\n\t\treturn true;\n\t}\n\tthrow new Error(\"Test run logger is not initialized\");\n}\n"]}
package/dist/package.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "sideEffects": false
4
- }
@@ -1,9 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- *
5
- * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
- */
7
- export declare const pkgName = "@fluid-internal/mocha-test-setup";
8
- export declare const pkgVersion = "2.101.1";
9
- //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,qCAAqC,CAAC;AAC1D,eAAO,MAAM,UAAU,YAAY,CAAC"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- *
6
- * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.pkgVersion = exports.pkgName = void 0;
10
- exports.pkgName = "@fluid-internal/mocha-test-setup";
11
- exports.pkgVersion = "2.101.1";
12
- //# sourceMappingURL=packageVersion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,kCAAkC,CAAC;AAC7C,QAAA,UAAU,GAAG,SAAS,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluid-internal/mocha-test-setup\";\nexport const pkgVersion = \"2.101.1\";\n"]}
package/tsconfig.cjs.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- // This config must be used in a "type": "commonjs" environment. (Use `fluid-tsc commonjs`.)
3
- "extends": "./tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "./dist",
6
- },
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext",
6
- },
7
- }