@fluid-internal/mocha-test-setup 2.50.0 → 2.51.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/CHANGELOG.md +4 -0
- package/dist/mochaHooks.d.ts +2 -1
- package/dist/mochaHooks.d.ts.map +1 -1
- package/dist/mochaHooks.js +18 -2
- package/dist/mochaHooks.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/mochaHooks.d.ts +2 -1
- package/lib/mochaHooks.d.ts.map +1 -1
- package/lib/mochaHooks.js +18 -2
- package/lib/mochaHooks.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/mocharc-common.cjs +6 -3
- package/package.json +3 -3
- package/src/mochaHooks.ts +20 -2
- package/src/packageVersion.ts +1 -1
package/CHANGELOG.md
CHANGED
package/dist/mochaHooks.d.ts
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export declare const mochaHooks: {
|
|
10
|
-
beforeAll(): void
|
|
10
|
+
beforeAll(): Promise<void>;
|
|
11
11
|
beforeEach(this: Mocha.Context): void;
|
|
12
12
|
afterEach(this: Mocha.Context): void;
|
|
13
|
+
afterAll(): Promise<void>;
|
|
13
14
|
};
|
|
14
15
|
//# sourceMappingURL=mochaHooks.d.ts.map
|
package/dist/mochaHooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mochaHooks.d.ts","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAoFH;;GAEG;AACH,eAAO,MAAM,UAAU;;
|
|
1
|
+
{"version":3,"file":"mochaHooks.d.ts","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAoFH;;GAEG;AACH,eAAO,MAAM,UAAU;;qBA+BL,MAAM,OAAO;oBAed,MAAM,OAAO;;CAyB7B,CAAC"}
|
package/dist/mochaHooks.js
CHANGED
|
@@ -100,12 +100,24 @@ let testLogger;
|
|
|
100
100
|
* @internal
|
|
101
101
|
*/
|
|
102
102
|
exports.mochaHooks = {
|
|
103
|
-
beforeAll() {
|
|
103
|
+
async beforeAll() {
|
|
104
104
|
// Code in our tests will call the global `getTestLogger` function to get a logger to use.
|
|
105
105
|
// First we call the version of that function that was (potentially) injected dynamicaly to get the logger that it
|
|
106
106
|
// provides and wrap it with a more intelligent logger which adds test-run-related context to all events logged
|
|
107
107
|
// through it. See the documentation on `FluidTestRunLogger` for details.
|
|
108
|
-
|
|
108
|
+
let originalLogger;
|
|
109
|
+
if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER === undefined) {
|
|
110
|
+
originalLogger = nullLogger;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const { createTestLogger } = await import(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);
|
|
114
|
+
if (typeof createTestLogger !== "function") {
|
|
115
|
+
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`);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
originalLogger = createTestLogger();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
109
121
|
testLogger = new FluidTestRunLogger(originalLogger);
|
|
110
122
|
// Then we redefine `getTestLogger` so it returns the wrapper logger.
|
|
111
123
|
// NOTE: if we have other global mocha hooks defined somewhere, they include a `beforeEach` hook, and the module in
|
|
@@ -147,6 +159,10 @@ exports.mochaHooks = {
|
|
|
147
159
|
// test (e.g. during a `before` or `after` hook), it doesn't log events with the name of the last test that ran.
|
|
148
160
|
testLogger.clearCurrentTest();
|
|
149
161
|
},
|
|
162
|
+
async afterAll() {
|
|
163
|
+
// After all tests ran, flush the logger to ensure all events are sent before the process exits.
|
|
164
|
+
await testLogger.flush();
|
|
165
|
+
},
|
|
150
166
|
};
|
|
151
167
|
globalThis.getMochaModule = () => {
|
|
152
168
|
return mochaModule;
|
package/dist/mochaHooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mochaHooks.js","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAIH,mDAAqC;AAErC,2DAA8C;AAE9C,wDAAwD;AACxD,2FAA2F;AAC3F,wGAAwG;AACxG,yDAAyD;AACzD,sCAAsC;AACtC,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAEjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;AACnD,MAAM,SAAS,GACd,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI;IACrC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC5C,CAAC,CAAC,SAAS,CAAC;AAEd,MAAM,OAAO,GAAQ,MAAM,CAAC;AAE5B;;;GAGG;AACH,MAAM,kBAAkB;IAGvB,IAAI,CAAC,KAA0B;QAC9B,6CAA6C;QAC7C,gDAAgD;QAChD,IAAI,KAAK,CAAC,SAAS,KAAK,kDAAkD,EAAE,CAAC;YAC5E,OAAO;QACR,CAAC;QAED,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACxC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC;QACvC,CAAC;QACD,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;YACtB,GAAG,KAAK;YACR,kGAAkG;YAClG,kEAAkE;YAClE,QAAQ,EAAE,SAAS,EAAE,QAAQ,IAAI,2BAAO;YACxC,OAAO,EAAE,IAAI,C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b,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 propsDict =\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) {\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: propsDict?.hostName ?? pkgName,\n\t\t\tdetails: JSON.stringify(propsDict),\n\t\t});\n\t}\n\tasync flush() {\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) {\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() {\n\t\tthis.currentTestName = undefined;\n\t}\n}\nconst nullLogger: ITelemetryBufferedLogger = {\n\tsend: () => {},\n\tflush: async () => {},\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 * @internal\n */\nexport const mochaHooks = {\n\tbeforeAll() {\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\tconst originalLogger = _global.getTestLogger?.() ?? nullLogger;\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\t\ttestLogger.setCurrentTest(this.currentTest?.fullTitle() ?? \"\");\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};\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"]}
|
|
1
|
+
{"version":3,"file":"mochaHooks.js","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAIH,mDAAqC;AAErC,2DAA8C;AAE9C,wDAAwD;AACxD,2FAA2F;AAC3F,wGAAwG;AACxG,yDAAyD;AACzD,sCAAsC;AACtC,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAEjD,MAAM,WAAW,GAAG,OAA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AAY,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 propsDict =\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) {\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: propsDict?.hostName ?? pkgName,\n\t\t\tdetails: JSON.stringify(propsDict),\n\t\t});\n\t}\n\tasync flush() {\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) {\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() {\n\t\tthis.currentTestName = undefined;\n\t}\n}\nconst nullLogger: ITelemetryBufferedLogger = {\n\tsend: () => {},\n\tflush: async () => {},\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 * @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}\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\t\ttestLogger.setCurrentTest(this.currentTest?.fullTitle() ?? \"\");\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() {\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/packageVersion.d.ts
CHANGED
|
@@ -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.
|
|
8
|
+
export declare const pkgVersion = "2.51.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluid-internal/mocha-test-setup";
|
|
11
|
-
exports.pkgVersion = "2.
|
|
11
|
+
exports.pkgVersion = "2.51.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
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,QAAQ,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.
|
|
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,QAAQ,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.51.0\";\n"]}
|
package/lib/mochaHooks.d.ts
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export declare const mochaHooks: {
|
|
10
|
-
beforeAll(): void
|
|
10
|
+
beforeAll(): Promise<void>;
|
|
11
11
|
beforeEach(this: Mocha.Context): void;
|
|
12
12
|
afterEach(this: Mocha.Context): void;
|
|
13
|
+
afterAll(): Promise<void>;
|
|
13
14
|
};
|
|
14
15
|
//# sourceMappingURL=mochaHooks.d.ts.map
|
package/lib/mochaHooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mochaHooks.d.ts","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAoFH;;GAEG;AACH,eAAO,MAAM,UAAU;;
|
|
1
|
+
{"version":3,"file":"mochaHooks.d.ts","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAoFH;;GAEG;AACH,eAAO,MAAM,UAAU;;qBA+BL,MAAM,OAAO;oBAed,MAAM,OAAO;;CAyB7B,CAAC"}
|
package/lib/mochaHooks.js
CHANGED
|
@@ -74,12 +74,24 @@ let testLogger;
|
|
|
74
74
|
* @internal
|
|
75
75
|
*/
|
|
76
76
|
export const mochaHooks = {
|
|
77
|
-
beforeAll() {
|
|
77
|
+
async beforeAll() {
|
|
78
78
|
// Code in our tests will call the global `getTestLogger` function to get a logger to use.
|
|
79
79
|
// First we call the version of that function that was (potentially) injected dynamicaly to get the logger that it
|
|
80
80
|
// provides and wrap it with a more intelligent logger which adds test-run-related context to all events logged
|
|
81
81
|
// through it. See the documentation on `FluidTestRunLogger` for details.
|
|
82
|
-
|
|
82
|
+
let originalLogger;
|
|
83
|
+
if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER === undefined) {
|
|
84
|
+
originalLogger = nullLogger;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const { createTestLogger } = await import(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);
|
|
88
|
+
if (typeof createTestLogger !== "function") {
|
|
89
|
+
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`);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
originalLogger = createTestLogger();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
83
95
|
testLogger = new FluidTestRunLogger(originalLogger);
|
|
84
96
|
// Then we redefine `getTestLogger` so it returns the wrapper logger.
|
|
85
97
|
// NOTE: if we have other global mocha hooks defined somewhere, they include a `beforeEach` hook, and the module in
|
|
@@ -121,6 +133,10 @@ export const mochaHooks = {
|
|
|
121
133
|
// test (e.g. during a `before` or `after` hook), it doesn't log events with the name of the last test that ran.
|
|
122
134
|
testLogger.clearCurrentTest();
|
|
123
135
|
},
|
|
136
|
+
async afterAll() {
|
|
137
|
+
// After all tests ran, flush the logger to ensure all events are sent before the process exits.
|
|
138
|
+
await testLogger.flush();
|
|
139
|
+
},
|
|
124
140
|
};
|
|
125
141
|
globalThis.getMochaModule = () => {
|
|
126
142
|
return mochaModule;
|
package/lib/mochaHooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mochaHooks.js","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,WAAW,MAAM,OAAO,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,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,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,4BAA4B;SACvC,CAAC,CAAC;IACJ,CAAC;IACD,SAAS;QACR,gCAAgC,CAAC,UAAU,CAAC,CAAC;QAC7C,UAAU,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,0BAA0B;YACrC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK;YAC9B,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ;YACpC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ;YACpC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO;YACrC,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;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 propsDict =\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) {\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: propsDict?.hostName ?? pkgName,\n\t\t\tdetails: JSON.stringify(propsDict),\n\t\t});\n\t}\n\tasync flush() {\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) {\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() {\n\t\tthis.currentTestName = undefined;\n\t}\n}\nconst nullLogger: ITelemetryBufferedLogger = {\n\tsend: () => {},\n\tflush: async () => {},\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 * @internal\n */\nexport const mochaHooks = {\n\tbeforeAll() {\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\tconst originalLogger = _global.getTestLogger?.() ?? nullLogger;\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\t\ttestLogger.setCurrentTest(this.currentTest?.fullTitle() ?? \"\");\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};\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"]}
|
|
1
|
+
{"version":3,"file":"mochaHooks.js","sourceRoot":"","sources":["../src/mochaHooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,WAAW,MAAM,OAAO,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,wDAAwD;AACxD,2FAA2F;AAC3F,wGAAwG;AACxG,yDAAyD;AACzD,sCAAsC;AACtC,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAEjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;AACnD,MAAM,SAAS,GACd,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI;IACrC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC5C,CAAC,CAAC,SAAS,CAAC;AAEd,MAAM,OAAO,GAAQ,MAAM,CAAC;AAE5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AAU,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,4BAA4B;SACvC,CAAC,CAAC;IACJ,CAAC;IACD,SAAS;QACR,gCAAgC,CAAC,UAAU,CAAC,CAAC;QAC7C,UAAU,CAAC,IAAI,CAAC;YACf,QAAQ,EAAE,SAAS;YACnB,SAAS,EAAE,0BAA0B;YACrC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK;YAC9B,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ;YACpC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ;YACpC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO;YACrC,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,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 propsDict =\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) {\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: propsDict?.hostName ?? pkgName,\n\t\t\tdetails: JSON.stringify(propsDict),\n\t\t});\n\t}\n\tasync flush() {\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) {\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() {\n\t\tthis.currentTestName = undefined;\n\t}\n}\nconst nullLogger: ITelemetryBufferedLogger = {\n\tsend: () => {},\n\tflush: async () => {},\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 * @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}\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\t\ttestLogger.setCurrentTest(this.currentTest?.fullTitle() ?? \"\");\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() {\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/lib/packageVersion.d.ts
CHANGED
|
@@ -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.
|
|
8
|
+
export declare const pkgVersion = "2.51.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -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,QAAQ,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.
|
|
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,QAAQ,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.51.0\";\n"]}
|
package/mocharc-common.cjs
CHANGED
|
@@ -41,9 +41,12 @@ function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testRepo
|
|
|
41
41
|
return mod;
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
if (process.env.
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER) {
|
|
45
|
+
const modulePath = require.resolve(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);
|
|
46
|
+
// Inject implementation of createTestLogger, put it first before mocha-test-setup
|
|
47
|
+
if (existsSync(modulePath)) {
|
|
48
|
+
requiredModulePaths.unshift(modulePath);
|
|
49
|
+
}
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
const config = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-internal/mocha-test-setup",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.51.0",
|
|
4
4
|
"description": "Utilities for Fluid tests",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"main": "dist/index.js",
|
|
31
31
|
"types": "dist/index.d.ts",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@fluid-internal/test-driver-definitions": "~2.
|
|
34
|
-
"@fluidframework/core-interfaces": "~2.
|
|
33
|
+
"@fluid-internal/test-driver-definitions": "~2.51.0",
|
|
34
|
+
"@fluidframework/core-interfaces": "~2.51.0",
|
|
35
35
|
"mocha": "^10.8.2",
|
|
36
36
|
"source-map-support": "^0.5.21"
|
|
37
37
|
},
|
package/src/mochaHooks.ts
CHANGED
|
@@ -89,13 +89,27 @@ let testLogger: FluidTestRunLogger;
|
|
|
89
89
|
* @internal
|
|
90
90
|
*/
|
|
91
91
|
export const mochaHooks = {
|
|
92
|
-
beforeAll() {
|
|
92
|
+
async beforeAll() {
|
|
93
93
|
// Code in our tests will call the global `getTestLogger` function to get a logger to use.
|
|
94
94
|
|
|
95
95
|
// First we call the version of that function that was (potentially) injected dynamicaly to get the logger that it
|
|
96
96
|
// provides and wrap it with a more intelligent logger which adds test-run-related context to all events logged
|
|
97
97
|
// through it. See the documentation on `FluidTestRunLogger` for details.
|
|
98
|
-
|
|
98
|
+
let originalLogger: ITelemetryBufferedLogger;
|
|
99
|
+
|
|
100
|
+
if (process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER === undefined) {
|
|
101
|
+
originalLogger = nullLogger;
|
|
102
|
+
} else {
|
|
103
|
+
const { createTestLogger } = await import(process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER);
|
|
104
|
+
if (typeof createTestLogger !== "function") {
|
|
105
|
+
throw new TypeError(
|
|
106
|
+
`Expected package '${process.env.FLUID_TEST_LOGGER_PKG_SPECIFIER}' to export a function, but got an object of type '${typeof createTestLogger}' instead`,
|
|
107
|
+
);
|
|
108
|
+
} else {
|
|
109
|
+
originalLogger = createTestLogger();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
99
113
|
testLogger = new FluidTestRunLogger(originalLogger);
|
|
100
114
|
|
|
101
115
|
// Then we redefine `getTestLogger` so it returns the wrapper logger.
|
|
@@ -141,6 +155,10 @@ export const mochaHooks = {
|
|
|
141
155
|
// test (e.g. during a `before` or `after` hook), it doesn't log events with the name of the last test that ran.
|
|
142
156
|
testLogger.clearCurrentTest();
|
|
143
157
|
},
|
|
158
|
+
async afterAll() {
|
|
159
|
+
// After all tests ran, flush the logger to ensure all events are sent before the process exits.
|
|
160
|
+
await testLogger.flush();
|
|
161
|
+
},
|
|
144
162
|
};
|
|
145
163
|
|
|
146
164
|
globalThis.getMochaModule = () => {
|
package/src/packageVersion.ts
CHANGED