@happy-dom/jest-environment 2.24.1 → 2.24.5
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 +66 -84
- package/bin/copy-package-json-for-lit.js +42 -0
- package/bin/copy-tsdef-for-lit.js +35 -0
- package/bin/transform-lit-require.js +64 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +7 -6
- package/lib/index.js.map +1 -1
- package/package.json +10 -5
- package/src/index.ts +7 -6
- package/test/lit-element/LitElement.test.ts +9 -4
- package/test/lit-element/LitElementComponent.ts +6 -12
@@ -1,92 +1,74 @@
|
|
1
|
-
/* eslint-disable */
|
1
|
+
/* eslint-disable no-console*/
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires*/
|
2
3
|
|
3
4
|
const Fs = require('fs');
|
4
5
|
const Path = require('path');
|
5
|
-
const litElementPath = Path.dirname(require.resolve('lit-element/package.json'));
|
6
|
-
const litHTMLPath = Path.dirname(require.resolve('lit-html/package.json'));
|
7
|
-
const litElementTSConfig = {
|
8
|
-
"compilerOptions": {
|
9
|
-
"module": "CommonJS",
|
10
|
-
"sourceMap": false,
|
11
|
-
"target": "ES5",
|
12
|
-
"preserveSymlinks": true,
|
13
|
-
"preserveWatchOutput": true,
|
14
|
-
"experimentalDecorators": true,
|
15
|
-
"allowSyntheticDefaultImports": false,
|
16
|
-
"allowJs": true,
|
17
|
-
"checkJs": false,
|
18
|
-
"skipLibCheck": true,
|
19
|
-
"resolveJsonModule": true,
|
20
|
-
"moduleResolution": "node",
|
21
|
-
"noResolve": true,
|
22
|
-
"incremental": true,
|
23
|
-
"tsBuildInfoFile": "lit-element-tsbuildinfo",
|
24
|
-
"lib": [
|
25
|
-
"dom",
|
26
|
-
"es2015",
|
27
|
-
"es2016"
|
28
|
-
],
|
29
|
-
"outDir": "../lib/node_modules/lit-element",
|
30
|
-
"baseUrl": ".",
|
31
|
-
"removeComments": true,
|
32
|
-
"rootDir": litElementPath
|
33
|
-
},
|
34
|
-
"include": [litElementPath],
|
35
|
-
"exclude": [litElementPath + '/src']
|
36
|
-
};
|
37
|
-
const litHTMLTSConfig = {
|
38
|
-
"compilerOptions": {
|
39
|
-
"module": "CommonJS",
|
40
|
-
"sourceMap": false,
|
41
|
-
"target": "ES5",
|
42
|
-
"preserveSymlinks": true,
|
43
|
-
"preserveWatchOutput": true,
|
44
|
-
"experimentalDecorators": true,
|
45
|
-
"allowSyntheticDefaultImports": false,
|
46
|
-
"allowJs": true,
|
47
|
-
"checkJs": false,
|
48
|
-
"skipLibCheck": true,
|
49
|
-
"resolveJsonModule": true,
|
50
|
-
"moduleResolution": "node",
|
51
|
-
"noResolve": true,
|
52
|
-
"incremental": true,
|
53
|
-
"tsBuildInfoFile": "lit-html-tsbuildinfo",
|
54
|
-
"lib": [
|
55
|
-
"dom",
|
56
|
-
"es2015",
|
57
|
-
"es2016"
|
58
|
-
],
|
59
|
-
"outDir": "../lib/node_modules/lit-html",
|
60
|
-
"baseUrl": ".",
|
61
|
-
"removeComments": true,
|
62
|
-
"rootDir": litHTMLPath
|
63
|
-
},
|
64
|
-
"include": [litHTMLPath],
|
65
|
-
"exclude": [litHTMLPath + '/src']
|
66
|
-
};
|
67
6
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
7
|
+
const LIBS = ['@lit/reactive-element', 'lit', 'lit-element', 'lit-html'];
|
8
|
+
|
9
|
+
function getTsConfig(lib) {
|
10
|
+
const split = require.resolve(lib).split('node_modules');
|
11
|
+
const modulePathSplit = split[1].split(Path.sep);
|
12
|
+
const modulePath = modulePathSplit[1].startsWith('@')
|
13
|
+
? modulePathSplit[1] + Path.sep + modulePathSplit[2]
|
14
|
+
: modulePathSplit[1];
|
15
|
+
const path = Path.join(split[0], 'node_modules', modulePath);
|
16
|
+
|
17
|
+
return {
|
18
|
+
compilerOptions: {
|
19
|
+
module: 'CommonJS',
|
20
|
+
sourceMap: false,
|
21
|
+
target: 'es5',
|
22
|
+
preserveSymlinks: true,
|
23
|
+
preserveWatchOutput: true,
|
24
|
+
experimentalDecorators: true,
|
25
|
+
allowSyntheticDefaultImports: false,
|
26
|
+
allowJs: true,
|
27
|
+
checkJs: false,
|
28
|
+
skipLibCheck: true,
|
29
|
+
resolveJsonModule: true,
|
30
|
+
moduleResolution: 'node',
|
31
|
+
noResolve: true,
|
32
|
+
incremental: true,
|
33
|
+
tsBuildInfoFile: lib.replace('@', '').replace(/[/\\]/g, '-') + '-tsbuildinfo',
|
34
|
+
lib: ['es2015', 'es2016', 'es2017'],
|
35
|
+
outDir: '../lib/node_modules/' + lib,
|
36
|
+
baseUrl: '.',
|
37
|
+
removeComments: true,
|
38
|
+
rootDir: path
|
39
|
+
},
|
40
|
+
include: [path],
|
41
|
+
exclude: [path + '/src']
|
42
|
+
};
|
83
43
|
}
|
84
44
|
|
85
|
-
function
|
86
|
-
|
45
|
+
async function writeTsConfigFile(lib) {
|
46
|
+
await Fs.promises.writeFile(
|
47
|
+
Path.resolve(`tmp/tsconfig.${lib.replace('@', '').replace(/[/\\]/g, '-')}.json`),
|
48
|
+
JSON.stringify(getTsConfig(lib), null, 4)
|
49
|
+
);
|
87
50
|
}
|
88
51
|
|
89
|
-
|
90
|
-
.
|
91
|
-
|
92
|
-
|
52
|
+
async function createTmpDirectory() {
|
53
|
+
await Fs.promises.mkdir(Path.resolve('tmp'));
|
54
|
+
}
|
55
|
+
|
56
|
+
async function writeLibFiles() {
|
57
|
+
await Promise.all(LIBS.map(lib => writeTsConfigFile(lib)));
|
58
|
+
}
|
59
|
+
|
60
|
+
async function main() {
|
61
|
+
try {
|
62
|
+
await Fs.promises.access(Path.resolve('tmp'));
|
63
|
+
} catch (error) {
|
64
|
+
await createTmpDirectory();
|
65
|
+
}
|
66
|
+
await writeLibFiles();
|
67
|
+
}
|
68
|
+
|
69
|
+
process.on('unhandledRejection', reason => {
|
70
|
+
console.error(reason);
|
71
|
+
process.exit(1);
|
72
|
+
});
|
73
|
+
|
74
|
+
main();
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/* eslint-disable no-console*/
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires*/
|
3
|
+
|
4
|
+
const Path = require('path');
|
5
|
+
const FS = require('fs');
|
6
|
+
|
7
|
+
const LIBS = ['@lit/reactive-element', 'lit', 'lit-element', 'lit-html'];
|
8
|
+
|
9
|
+
function getLibPath(lib) {
|
10
|
+
const split = require.resolve(lib).split('node_modules');
|
11
|
+
const modulePathSplit = split[1].split(Path.sep);
|
12
|
+
const modulePath = modulePathSplit[1].startsWith('@')
|
13
|
+
? modulePathSplit[1] + Path.sep + modulePathSplit[2]
|
14
|
+
: modulePathSplit[1];
|
15
|
+
|
16
|
+
return Path.join(split[0], 'node_modules', modulePath);
|
17
|
+
}
|
18
|
+
|
19
|
+
async function writePackageJson(from, to) {
|
20
|
+
const packageJson = require(from);
|
21
|
+
delete packageJson.type;
|
22
|
+
delete packageJson.exports;
|
23
|
+
await FS.promises.writeFile(to, JSON.stringify(packageJson, null, 4));
|
24
|
+
}
|
25
|
+
|
26
|
+
async function main() {
|
27
|
+
await Promise.all(
|
28
|
+
LIBS.map(lib =>
|
29
|
+
writePackageJson(
|
30
|
+
Path.join(getLibPath(lib), 'package.json'),
|
31
|
+
Path.resolve(Path.join('lib', 'node_modules', lib, 'package.json'))
|
32
|
+
)
|
33
|
+
)
|
34
|
+
);
|
35
|
+
}
|
36
|
+
|
37
|
+
process.on('unhandledRejection', reason => {
|
38
|
+
console.error(reason);
|
39
|
+
process.exit(1);
|
40
|
+
});
|
41
|
+
|
42
|
+
main();
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/* eslint-disable no-console*/
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires*/
|
3
|
+
|
4
|
+
const Path = require('path');
|
5
|
+
const CPY = require('cpy');
|
6
|
+
|
7
|
+
const LIBS = ['@lit/reactive-element', 'lit', 'lit-element', 'lit-html'];
|
8
|
+
|
9
|
+
function getLibPath(lib) {
|
10
|
+
const split = require.resolve(lib).split('node_modules');
|
11
|
+
const modulePathSplit = split[1].split(Path.sep);
|
12
|
+
const modulePath = modulePathSplit[1].startsWith('@')
|
13
|
+
? modulePathSplit[1] + Path.sep + modulePathSplit[2]
|
14
|
+
: modulePathSplit[1];
|
15
|
+
|
16
|
+
return Path.join(split[0], 'node_modules', modulePath);
|
17
|
+
}
|
18
|
+
|
19
|
+
async function main() {
|
20
|
+
await Promise.all(
|
21
|
+
LIBS.map(lib =>
|
22
|
+
CPY(
|
23
|
+
[Path.join(getLibPath(lib), '*.d.ts')],
|
24
|
+
Path.resolve(Path.join('lib', 'node_modules', lib))
|
25
|
+
)
|
26
|
+
)
|
27
|
+
);
|
28
|
+
}
|
29
|
+
|
30
|
+
process.on('unhandledRejection', reason => {
|
31
|
+
console.error(reason);
|
32
|
+
process.exit(1);
|
33
|
+
});
|
34
|
+
|
35
|
+
main();
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/* eslint-disable no-console*/
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires*/
|
3
|
+
|
4
|
+
const FS = require('fs');
|
5
|
+
const Path = require('path');
|
6
|
+
const Glob = require('glob');
|
7
|
+
|
8
|
+
const LIBS = ['@lit/reactive-element', 'lit', 'lit-element', 'lit-html'];
|
9
|
+
|
10
|
+
function getFiles(lib) {
|
11
|
+
return new Promise((resolve, reject) => {
|
12
|
+
Glob(
|
13
|
+
`${Path.resolve('./lib/node_modules/' + lib)}/**/*.js`,
|
14
|
+
{ nodir: true },
|
15
|
+
(error, files) => {
|
16
|
+
if (error) {
|
17
|
+
reject(error);
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
resolve(files);
|
21
|
+
}
|
22
|
+
);
|
23
|
+
});
|
24
|
+
}
|
25
|
+
|
26
|
+
async function transformFile(lib, file) {
|
27
|
+
const data = (await FS.promises.readFile(file)).toString();
|
28
|
+
const regexp = /require\(["']([^"']+)["']\)/gm;
|
29
|
+
const libDirectory = lib.split('/').length > 1 ? '../../' : '../';
|
30
|
+
let newData = data;
|
31
|
+
let match = null;
|
32
|
+
|
33
|
+
while ((match = regexp.exec(data))) {
|
34
|
+
for (const externalLib of LIBS) {
|
35
|
+
if (match[1].startsWith(externalLib)) {
|
36
|
+
newData = newData.replace(match[0], `require("${libDirectory}${match[1]}")`);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
if (data !== newData) {
|
42
|
+
await FS.promises.writeFile(file, newData);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
async function transformLib(lib) {
|
47
|
+
const files = await getFiles(lib);
|
48
|
+
const promises = [];
|
49
|
+
for (const file of files) {
|
50
|
+
promises.push(transformFile(lib, file));
|
51
|
+
}
|
52
|
+
await Promise.all(promises);
|
53
|
+
}
|
54
|
+
|
55
|
+
async function main() {
|
56
|
+
await Promise.all(LIBS.map(lib => transformLib(lib)));
|
57
|
+
}
|
58
|
+
|
59
|
+
process.on('unhandledRejection', reason => {
|
60
|
+
console.error(reason);
|
61
|
+
process.exit(1);
|
62
|
+
});
|
63
|
+
|
64
|
+
main();
|
package/lib/index.d.ts
CHANGED
@@ -3,6 +3,7 @@ import VM from 'vm';
|
|
3
3
|
import { ModuleMocker } from 'jest-mock';
|
4
4
|
import { LegacyFakeTimers, ModernFakeTimers } from '@jest/fake-timers';
|
5
5
|
import { JestEnvironment, EnvironmentContext } from '@jest/environment';
|
6
|
+
import { Window } from 'happy-dom';
|
6
7
|
import { Script } from 'vm';
|
7
8
|
import { Global, Config } from '@jest/types';
|
8
9
|
/**
|
@@ -11,6 +12,7 @@ import { Global, Config } from '@jest/types';
|
|
11
12
|
export default class HappyDOMEnvironment implements JestEnvironment {
|
12
13
|
fakeTimers: LegacyFakeTimers<number>;
|
13
14
|
fakeTimersModern: ModernFakeTimers;
|
15
|
+
window: Window;
|
14
16
|
global: Global.Global;
|
15
17
|
moduleMocker: ModuleMocker;
|
16
18
|
/**
|
package/lib/index.js
CHANGED
@@ -77,8 +77,9 @@ var HappyDOMEnvironment = /** @class */ (function () {
|
|
77
77
|
function HappyDOMEnvironment(config, options) {
|
78
78
|
this.fakeTimers = null;
|
79
79
|
this.fakeTimersModern = null;
|
80
|
-
this.
|
81
|
-
this.
|
80
|
+
this.window = new happy_dom_1.Window();
|
81
|
+
this.global = this.window;
|
82
|
+
this.moduleMocker = new jest_mock_1.ModuleMocker(this.window);
|
82
83
|
vm_1.default.createContext(this.global);
|
83
84
|
// Functions are not an instanceof the "Function" class in the VM context, so therefore we set it to the used "Function" class.
|
84
85
|
vm_1.default.runInContext('window.Function = (() => {}).constructor;', this.global);
|
@@ -87,15 +88,15 @@ var HappyDOMEnvironment = /** @class */ (function () {
|
|
87
88
|
// TODO: Remove this ASAP as it currently causes tests to run really slow.
|
88
89
|
this.global.Buffer = Buffer;
|
89
90
|
// Needed as Jest is using it
|
90
|
-
this.
|
91
|
-
JestUtil.installCommonGlobals(this.
|
91
|
+
this.window.global = this.global;
|
92
|
+
JestUtil.installCommonGlobals(this.window, config.globals);
|
92
93
|
if (options && options.console) {
|
93
94
|
this.global.console = options.console;
|
94
95
|
this.global.window['console'] = options.console;
|
95
96
|
}
|
96
97
|
this.fakeTimers = new fake_timers_1.LegacyFakeTimers({
|
97
98
|
config: config,
|
98
|
-
global: this.
|
99
|
+
global: this.window,
|
99
100
|
moduleMocker: this.moduleMocker,
|
100
101
|
timerConfig: {
|
101
102
|
idToRef: function (id) { return id; },
|
@@ -104,7 +105,7 @@ var HappyDOMEnvironment = /** @class */ (function () {
|
|
104
105
|
});
|
105
106
|
this.fakeTimersModern = new fake_timers_1.ModernFakeTimers({
|
106
107
|
config: config,
|
107
|
-
global: this.
|
108
|
+
global: this.window
|
108
109
|
});
|
109
110
|
}
|
110
111
|
/**
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,0CAAoB;AACpB,kDAAsC;AACtC,uCAAyC;AACzC,iDAAuE;AAEvE,uCAAmC;AAInC;;GAEG;AACH;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,0CAAoB;AACpB,kDAAsC;AACtC,uCAAyC;AACzC,iDAAuE;AAEvE,uCAAmC;AAInC;;GAEG;AACH;IAOC;;;;;OAKG;IACH,6BAAY,MAA4B,EAAE,OAA4B;QAZ/D,eAAU,GAA6B,IAAI,CAAC;QAC5C,qBAAgB,GAAqB,IAAI,CAAC;QAC1C,WAAM,GAAG,IAAI,kBAAM,EAAE,CAAC;QACtB,WAAM,GAA2C,IAAI,CAAC,MAAO,CAAC;QAC9D,iBAAY,GAAiB,IAAI,wBAAY,CAA8B,IAAI,CAAC,MAAO,CAAC,CAAC;QAS/F,YAAE,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE9B,+HAA+H;QAC/H,YAAE,CAAC,YAAY,CAAC,2CAA2C,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAE1E,oHAAoH;QACpH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,GAAG,GAAG,CAAC;QAExC,0EAA0E;QAC1E,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAE5B,6BAA6B;QAC7B,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAEjC,QAAQ,CAAC,oBAAoB,CAA8B,IAAI,CAAC,MAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAEzF,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE;YAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;SAChD;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,8BAAgB,CAAC;YACtC,MAAM,QAAA;YACN,MAAM,EAA+B,IAAI,CAAC,MAAO;YACjD,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,WAAW,EAAE;gBACZ,OAAO,EAAE,UAAC,EAAU,IAAK,OAAA,EAAE,EAAF,CAAE;gBAC3B,OAAO,EAAE,UAAC,GAAW,IAAK,OAAA,GAAG,EAAH,CAAG;aAC7B;SACD,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,GAAG,IAAI,8BAAgB,CAAC;YAC5C,MAAM,QAAA;YACN,MAAM,EAA+B,IAAI,CAAC,MAAO;SACjD,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACU,mCAAK,GAAlB;;;;KAAsC;IAEtC;;;;OAIG;IACU,sCAAQ,GAArB;;;gBACC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;gBAC1B,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;gBAChC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;gBAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACnB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;gBACzB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;gBACvB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;;;;KAC7B;IAED;;;;;OAKG;IACI,uCAAS,GAAhB,UAAiB,MAAc;QAC9B,OAAO,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACI,0CAAY,GAAnB;QACC,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IACF,0BAAC;AAAD,CAAC,AA5FD,IA4FC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@happy-dom/jest-environment",
|
3
|
-
"version": "2.24.
|
3
|
+
"version": "2.24.5",
|
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",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"access": "public"
|
26
26
|
},
|
27
27
|
"scripts": {
|
28
|
-
"compile": "node ./bin/build-lit-ts-config && tsc --project tmp/tsconfig.lit-element.json && tsc --project tmp/tsconfig.lit-html.json && tsc",
|
28
|
+
"compile": "node ./bin/build-lit-ts-config && tsc --project tmp/tsconfig.lit-reactive-element.json && tsc --project tmp/tsconfig.lit-element.json && tsc --project tmp/tsconfig.lit-html.json && tsc --project tmp/tsconfig.lit.json && node ./bin/transform-lit-require.js && node ./bin/copy-tsdef-for-lit.js && node ./bin/copy-package-json-for-lit.js && tsc",
|
29
29
|
"watch": "npm run compile && tsc -w --preserveWatchOutput",
|
30
30
|
"lint": "eslint --ignore-path .gitignore --max-warnings 0 .",
|
31
31
|
"lint:fix": "eslint --ignore-path .gitignore --max-warnings 0 --fix .",
|
@@ -53,7 +53,7 @@
|
|
53
53
|
"@jest/environment": "^27.0.3",
|
54
54
|
"@jest/fake-timers": "^27.0.3",
|
55
55
|
"@jest/types": "^27.0.2",
|
56
|
-
"happy-dom": "^2.24.
|
56
|
+
"happy-dom": "^2.24.5",
|
57
57
|
"jest-mock": "^27.0.3",
|
58
58
|
"jest-util": "^27.0.2"
|
59
59
|
},
|
@@ -63,10 +63,12 @@
|
|
63
63
|
"@angular/core": "^10.0.7",
|
64
64
|
"@angular/platform-browser": "^10.0.7",
|
65
65
|
"@angular/platform-browser-dynamic": "^10.0.7",
|
66
|
+
"@lit/reactive-element": "^1.0.1",
|
66
67
|
"@types/jest": "^26.0.23",
|
67
68
|
"@types/node": "^15.6.0",
|
68
69
|
"@typescript-eslint/eslint-plugin": "^4.24.0",
|
69
70
|
"@typescript-eslint/parser": "^4.24.0",
|
71
|
+
"cpy": "^8.1.2",
|
70
72
|
"eslint": "^7.27.0",
|
71
73
|
"eslint-config-prettier": "^6.7.0",
|
72
74
|
"eslint-plugin-filenames": "^1.3.2",
|
@@ -75,9 +77,12 @@
|
|
75
77
|
"eslint-plugin-jsdoc": "^30.4.0",
|
76
78
|
"eslint-plugin-json": "^2.0.1",
|
77
79
|
"eslint-plugin-prettier": "^3.4.0",
|
80
|
+
"glob": "^7.1.6",
|
78
81
|
"jest": "^27.0.4",
|
79
82
|
"jquery": "^3.5.1",
|
80
|
-
"lit
|
83
|
+
"lit": "^2.0.2",
|
84
|
+
"lit-element": "^3.0.0",
|
85
|
+
"lit-html": "^2.0.0",
|
81
86
|
"prettier": "^1.19.1",
|
82
87
|
"react": "^16.13.1",
|
83
88
|
"react-dom": "^16.13.1",
|
@@ -86,5 +91,5 @@
|
|
86
91
|
"vue": "^2.6.12",
|
87
92
|
"zone.js": "^0.10.3"
|
88
93
|
},
|
89
|
-
"gitHead": "
|
94
|
+
"gitHead": "e0f4f0203b1a258596eff7d2ae322f4947381df7"
|
90
95
|
}
|
package/src/index.ts
CHANGED
@@ -15,8 +15,9 @@ import { Global, Config } from '@jest/types';
|
|
15
15
|
export default class HappyDOMEnvironment implements JestEnvironment {
|
16
16
|
public fakeTimers: LegacyFakeTimers<number> = null;
|
17
17
|
public fakeTimersModern: ModernFakeTimers = null;
|
18
|
-
public
|
19
|
-
public
|
18
|
+
public window = new Window();
|
19
|
+
public global: Global.Global = <Global.Global>(<unknown>this.window);
|
20
|
+
public moduleMocker: ModuleMocker = new ModuleMocker(<typeof globalThis>(<unknown>this.window));
|
20
21
|
|
21
22
|
/**
|
22
23
|
* Constructor.
|
@@ -37,9 +38,9 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
37
38
|
this.global.Buffer = Buffer;
|
38
39
|
|
39
40
|
// Needed as Jest is using it
|
40
|
-
this.
|
41
|
+
this.window.global = this.global;
|
41
42
|
|
42
|
-
JestUtil.installCommonGlobals(this.
|
43
|
+
JestUtil.installCommonGlobals(<typeof globalThis>(<unknown>this.window), config.globals);
|
43
44
|
|
44
45
|
if (options && options.console) {
|
45
46
|
this.global.console = options.console;
|
@@ -48,7 +49,7 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
48
49
|
|
49
50
|
this.fakeTimers = new LegacyFakeTimers({
|
50
51
|
config,
|
51
|
-
global: this.
|
52
|
+
global: <typeof globalThis>(<unknown>this.window),
|
52
53
|
moduleMocker: this.moduleMocker,
|
53
54
|
timerConfig: {
|
54
55
|
idToRef: (id: number) => id,
|
@@ -58,7 +59,7 @@ export default class HappyDOMEnvironment implements JestEnvironment {
|
|
58
59
|
|
59
60
|
this.fakeTimersModern = new ModernFakeTimers({
|
60
61
|
config,
|
61
|
-
global: this.
|
62
|
+
global: <typeof globalThis>(<unknown>this.window)
|
62
63
|
});
|
63
64
|
}
|
64
65
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import LitElementComponent from './LitElementComponent';
|
1
2
|
import './LitElementComponent';
|
2
3
|
|
3
4
|
const PROP1 = 'PROP1';
|
@@ -12,18 +13,22 @@ describe('LitElementComponent', () => {
|
|
12
13
|
});
|
13
14
|
|
14
15
|
it('Tests integration.', () => {
|
15
|
-
const
|
16
|
+
const litElement = <LitElementComponent>document.body.querySelector('lit-element-component');
|
17
|
+
const shadowRoot = litElement.shadowRoot;
|
16
18
|
|
17
19
|
expect(document.body.innerHTML).toBe(
|
18
20
|
`<lit-element-component prop1="${PROP1}"></lit-element-component>`
|
19
21
|
);
|
20
22
|
|
21
23
|
expect(shadowRoot.querySelector('span').innerText).toBe(PROP1);
|
22
|
-
expect(
|
24
|
+
expect(
|
25
|
+
shadowRoot.innerHTML
|
26
|
+
.replace(/[\s]/gm, '')
|
27
|
+
.replace(/<!--\?lit\$[0-9]+\$-->/gm, '<!--?lit$123456$-->')
|
28
|
+
).toBe(
|
23
29
|
`
|
24
30
|
<!---->Some text
|
25
|
-
<span
|
26
|
-
<!---->
|
31
|
+
<span><!--?lit$123456$-->${PROP1}</span>!
|
27
32
|
<style>
|
28
33
|
span {
|
29
34
|
color: green;
|
@@ -1,25 +1,19 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
TemplateResult,
|
4
|
-
html,
|
5
|
-
css,
|
6
|
-
customElement,
|
7
|
-
property
|
8
|
-
} from '../../lib/node_modules/lit-element/lit-element';
|
1
|
+
import { LitElement, TemplateResult, html, css, CSSResult } from '../../lib/node_modules/lit';
|
2
|
+
import { customElement, property } from '../../lib/node_modules/lit/decorators';
|
9
3
|
|
10
4
|
/**
|
11
5
|
*
|
12
6
|
*/
|
13
7
|
@customElement('lit-element-component')
|
14
|
-
export class LitElementComponent extends LitElement {
|
15
|
-
public static styles = css`
|
8
|
+
export default class LitElementComponent extends LitElement {
|
9
|
+
public static styles: CSSResult = css`
|
16
10
|
span {
|
17
11
|
color: green;
|
18
12
|
}
|
19
13
|
`;
|
20
14
|
|
21
|
-
@property({ type:
|
22
|
-
public prop1 = null;
|
15
|
+
@property({ type: String })
|
16
|
+
public prop1: string = null;
|
23
17
|
|
24
18
|
/**
|
25
19
|
* Renders the component.
|