@happy-dom/jest-environment 2.54.0 → 3.1.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/bin/build-lit-ts-config.js +1 -1
- package/lib/index.js +26 -77
- package/lib/index.js.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +1 -3
- package/tsconfig.json +1 -1
package/lib/index.js
CHANGED
@@ -23,90 +23,49 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
__setModuleDefault(result, mod);
|
24
24
|
return result;
|
25
25
|
};
|
26
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
27
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
28
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
29
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
30
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
31
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
32
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
33
|
-
});
|
34
|
-
};
|
35
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
36
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
37
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
38
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
39
|
-
function step(op) {
|
40
|
-
if (f) throw new TypeError("Generator is already executing.");
|
41
|
-
while (_) try {
|
42
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
43
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
44
|
-
switch (op[0]) {
|
45
|
-
case 0: case 1: t = op; break;
|
46
|
-
case 4: _.label++; return { value: op[1], done: false };
|
47
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
48
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
49
|
-
default:
|
50
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
51
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
52
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
53
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
54
|
-
if (t[2]) _.ops.pop();
|
55
|
-
_.trys.pop(); continue;
|
56
|
-
}
|
57
|
-
op = body.call(thisArg, _);
|
58
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
59
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
60
|
-
}
|
61
|
-
};
|
62
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
63
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
64
|
-
};
|
65
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
var happy_dom_1 = require("happy-dom");
|
27
|
+
const JestUtil = __importStar(require("jest-util"));
|
28
|
+
const jest_mock_1 = require("jest-mock");
|
29
|
+
const fake_timers_1 = require("@jest/fake-timers");
|
30
|
+
const happy_dom_1 = require("happy-dom");
|
71
31
|
/**
|
72
32
|
* Happy DOM Jest Environment.
|
73
33
|
*/
|
74
|
-
|
34
|
+
class HappyDOMEnvironment {
|
75
35
|
/**
|
76
36
|
* Constructor.
|
77
37
|
*
|
78
38
|
* @param config Jest config.
|
79
39
|
* @param options Options.
|
80
40
|
*/
|
81
|
-
|
41
|
+
constructor(config, options) {
|
82
42
|
this.fakeTimers = null;
|
83
43
|
this.fakeTimersModern = null;
|
84
44
|
this.window = new happy_dom_1.Window();
|
85
45
|
this.global = this.window;
|
86
46
|
this.moduleMocker = new jest_mock_1.ModuleMocker(this.window);
|
87
|
-
vm_1.default.createContext(this.global);
|
88
47
|
// Node's error-message stack size is limited to 10, but it's pretty useful to see more than that when a test fails.
|
89
48
|
this.global.Error.stackTraceLimit = 100;
|
90
49
|
// TODO: Remove this ASAP as it currently causes tests to run really slow.
|
91
50
|
this.global.Buffer = Buffer;
|
92
51
|
// Needed as Jest is using it
|
93
|
-
this.window
|
52
|
+
this.window['global'] = this.global;
|
94
53
|
JestUtil.installCommonGlobals(this.window, config.globals);
|
95
54
|
if (options && options.console) {
|
96
55
|
this.global.console = options.console;
|
97
56
|
this.global.window['console'] = options.console;
|
98
57
|
}
|
99
58
|
this.fakeTimers = new fake_timers_1.LegacyFakeTimers({
|
100
|
-
config
|
59
|
+
config,
|
101
60
|
global: this.window,
|
102
61
|
moduleMocker: this.moduleMocker,
|
103
62
|
timerConfig: {
|
104
|
-
idToRef:
|
105
|
-
refToId:
|
63
|
+
idToRef: (id) => id,
|
64
|
+
refToId: (ref) => ref
|
106
65
|
}
|
107
66
|
});
|
108
67
|
this.fakeTimersModern = new fake_timers_1.ModernFakeTimers({
|
109
|
-
config
|
68
|
+
config,
|
110
69
|
global: this.window
|
111
70
|
});
|
112
71
|
}
|
@@ -115,48 +74,38 @@ var HappyDOMEnvironment = /** @class */ (function () {
|
|
115
74
|
*
|
116
75
|
* @returns Promise.
|
117
76
|
*/
|
118
|
-
|
119
|
-
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
120
|
-
return [2 /*return*/];
|
121
|
-
}); });
|
122
|
-
};
|
77
|
+
async setup() { }
|
123
78
|
/**
|
124
79
|
* Teardown.
|
125
80
|
*
|
126
81
|
* @returns Promise.
|
127
82
|
*/
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
this.fakeTimersModern = null;
|
138
|
-
return [2 /*return*/];
|
139
|
-
});
|
140
|
-
});
|
141
|
-
};
|
83
|
+
async teardown() {
|
84
|
+
this.fakeTimers.dispose();
|
85
|
+
this.fakeTimersModern.dispose();
|
86
|
+
this.global.happyDOM['cancelAsync']();
|
87
|
+
this.global = null;
|
88
|
+
this.moduleMocker = null;
|
89
|
+
this.fakeTimers = null;
|
90
|
+
this.fakeTimersModern = null;
|
91
|
+
}
|
142
92
|
/**
|
143
93
|
* Runs a script.
|
144
94
|
*
|
145
95
|
* @param script Script.
|
146
96
|
* @returns Result.
|
147
97
|
*/
|
148
|
-
|
98
|
+
runScript(script) {
|
149
99
|
return script.runInContext(this.global);
|
150
|
-
}
|
100
|
+
}
|
151
101
|
/**
|
152
102
|
* Returns the VM context.
|
153
103
|
*
|
154
104
|
* @returns Context.
|
155
105
|
*/
|
156
|
-
|
106
|
+
getVmContext() {
|
157
107
|
return this.global;
|
158
|
-
}
|
159
|
-
|
160
|
-
}());
|
108
|
+
}
|
109
|
+
}
|
161
110
|
exports.default = HappyDOMEnvironment;
|
162
111
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6CAA6C
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;;AAG7C,oDAAsC;AACtC,yCAAyC;AACzC,mDAAuE;AAEvE,yCAAmC;AAInC;;GAEG;AACH,MAAqB,mBAAmB;IAOvC;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,OAA4B;QAZ/D,eAAU,GAA6B,IAAI,CAAC;QAC5C,qBAAgB,GAAqB,IAAI,CAAC;QAC1C,WAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;QAC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gBAAgB,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,MAAc;QAC9B,OAAO,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACI,YAAY;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AAvFD,sCAuFC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@happy-dom/jest-environment",
|
3
|
-
"version": "
|
3
|
+
"version": "3.1.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"homepage": "https://github.com/capricorn86/happy-dom/tree/master/packages/jest-environment",
|
6
6
|
"repository": "https://github.com/capricorn86/happy-dom",
|
@@ -31,7 +31,6 @@
|
|
31
31
|
"lint:fix": "eslint --ignore-path .gitignore --max-warnings 0 --fix .",
|
32
32
|
"test": "jest",
|
33
33
|
"test:watch": "jest --runInBand --watch",
|
34
|
-
"test:update-snapshot": "jest --runInBand --updateSnapshot",
|
35
34
|
"test:debug": "node --inspect-brk ./node_modules/.bin/jest --runInBand"
|
36
35
|
},
|
37
36
|
"jest": {
|
@@ -53,7 +52,7 @@
|
|
53
52
|
"@jest/environment": "^27.5.1",
|
54
53
|
"@jest/fake-timers": "^27.5.1",
|
55
54
|
"@jest/types": "^27.5.1",
|
56
|
-
"happy-dom": "^
|
55
|
+
"happy-dom": "^3.1.0",
|
57
56
|
"jest-mock": "^27.5.1",
|
58
57
|
"jest-util": "^27.5.1"
|
59
58
|
},
|
@@ -91,5 +90,5 @@
|
|
91
90
|
"vue": "^3.2.31",
|
92
91
|
"zone.js": "^0.10.3"
|
93
92
|
},
|
94
|
-
"gitHead": "
|
93
|
+
"gitHead": "83e3b256ed578d1507a3f24f0fff4e8c1e8d6e0e"
|
95
94
|
}
|
package/src/index.ts
CHANGED
@@ -26,8 +26,6 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
26
26
|
* @param options Options.
|
27
27
|
*/
|
28
28
|
constructor(config: Config.ProjectConfig, options?: EnvironmentContext) {
|
29
|
-
VM.createContext(this.global);
|
30
|
-
|
31
29
|
// Node's error-message stack size is limited to 10, but it's pretty useful to see more than that when a test fails.
|
32
30
|
this.global.Error.stackTraceLimit = 100;
|
33
31
|
|
@@ -35,7 +33,7 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
35
33
|
this.global.Buffer = Buffer;
|
36
34
|
|
37
35
|
// Needed as Jest is using it
|
38
|
-
this.window
|
36
|
+
this.window['global'] = this.global;
|
39
37
|
|
40
38
|
JestUtil.installCommonGlobals(<typeof globalThis>(<unknown>this.window), config.globals);
|
41
39
|
|