|
1
|
"use strict"; |
|
2
|
var __create = Object.create; |
|
3
|
var __defProp = Object.defineProperty; |
|
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
5
|
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
6
|
var __getProtoOf = Object.getPrototypeOf; |
|
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
8
|
var __export = (target, all) => { |
|
9
|
for (var name in all) |
|
10
|
__defProp(target, name, { get: all[name], enumerable: true }); |
|
11
|
}; |
|
12
|
var __copyProps = (to, from, except, desc) => { |
|
13
|
if (from && typeof from === "object" || typeof from === "function") { |
|
14
|
for (let key of __getOwnPropNames(from)) |
|
15
|
if (!__hasOwnProp.call(to, key) && key !== except) |
|
16
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
17
|
} |
|
18
|
return to; |
|
19
|
}; |
|
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
|
21
|
// If the importer is in node compatibility mode or this is not an ESM |
|
22
|
// file that has been converted to a CommonJS file using a Babel- |
|
23
|
// compatible transform (i.e. "__esModule" has not been set), then set |
|
24
|
// "default" to the CommonJS "module.exports" for node compatibility. |
|
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
|
26
|
mod |
|
27
|
)); |
|
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
|
29
|
var testLoader_exports = {}; |
|
30
|
__export(testLoader_exports, { |
|
31
|
defaultTimeout: () => defaultTimeout, |
|
32
|
loadTestFile: () => loadTestFile |
|
33
|
}); |
|
34
|
module.exports = __toCommonJS(testLoader_exports); |
|
35
|
var import_path = __toESM(require("path")); |
|
36
|
var import_util = __toESM(require("util")); |
|
37
|
var esmLoaderHost = __toESM(require("./esmLoaderHost")); |
|
38
|
var import_globals = require("./globals"); |
|
39
|
var import_test = require("./test"); |
|
40
|
var import_compilationCache = require("../transform/compilationCache"); |
|
41
|
var import_transform = require("../transform/transform"); |
|
42
|
var import_util2 = require("../util"); |
|
43
|
const defaultTimeout = 3e4; |
|
44
|
const cachedFileSuites = /* @__PURE__ */ new Map(); |
|
45
|
async function loadTestFile(file, config, testErrors) { |
|
46
|
if (cachedFileSuites.has(file)) |
|
47
|
return cachedFileSuites.get(file); |
|
48
|
const suite = new import_test.Suite(import_path.default.relative(config.config.rootDir, file) || import_path.default.basename(file), "file"); |
|
49
|
suite._requireFile = file; |
|
50
|
suite.location = { file, line: 0, column: 0 }; |
|
51
|
suite._tags = [...config.config.tags]; |
|
52
|
(0, import_globals.setCurrentlyLoadingFileSuite)(suite); |
|
53
|
if (!(0, import_globals.isWorkerProcess)()) { |
|
54
|
(0, import_compilationCache.startCollectingFileDeps)(); |
|
55
|
await esmLoaderHost.startCollectingFileDeps(); |
|
56
|
} |
|
57
|
try { |
|
58
|
await (0, import_transform.requireOrImport)(file); |
|
59
|
cachedFileSuites.set(file, suite); |
|
60
|
} catch (e) { |
|
61
|
if (!testErrors) |
|
62
|
throw e; |
|
63
|
testErrors.push(serializeLoadError(file, e)); |
|
64
|
} finally { |
|
65
|
(0, import_globals.setCurrentlyLoadingFileSuite)(void 0); |
|
66
|
if (!(0, import_globals.isWorkerProcess)()) { |
|
67
|
(0, import_compilationCache.stopCollectingFileDeps)(file); |
|
68
|
await esmLoaderHost.stopCollectingFileDeps(file); |
|
69
|
} |
|
70
|
} |
|
71
|
{ |
|
72
|
const files = /* @__PURE__ */ new Set(); |
|
73
|
suite.allTests().map((t) => files.add(t.location.file)); |
|
74
|
if (files.size === 1) { |
|
75
|
const mappedFile = files.values().next().value; |
|
76
|
if (suite.location.file !== mappedFile) { |
|
77
|
if (import_path.default.extname(mappedFile) !== import_path.default.extname(suite.location.file)) |
|
78
|
suite.location.file = mappedFile; |
|
79
|
} |
|
80
|
} |
|
81
|
} |
|
82
|
return suite; |
|
83
|
} |
|
84
|
function serializeLoadError(file, error) { |
|
85
|
if (error instanceof Error) { |
|
86
|
const result = (0, import_util2.filterStackTrace)(error); |
|
87
|
const loc = error.loc; |
|
88
|
result.location = loc ? { |
|
89
|
file, |
|
90
|
line: loc.line || 0, |
|
91
|
column: loc.column || 0 |
|
92
|
} : void 0; |
|
93
|
return result; |
|
94
|
} |
|
95
|
return { value: import_util.default.inspect(error) }; |
|
96
|
} |
|
97
|
// Annotate the CommonJS export names for ESM import in node: |
|
98
|
0 && (module.exports = { |
|
99
|
defaultTimeout, |
|
100
|
loadTestFile |
|
101
|
}); |
|
102
|
|