jest-preset-angular 8.3.2 → 8.4.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 +440 -0
- package/LICENSE.md +21 -0
- package/README.md +40 -462
- package/build/AngularNoNgAttributesSnapshotSerializer.js +18 -35
- package/build/AngularSnapshotSerializer.js +20 -20
- package/build/HTMLCommentSerializer.js +9 -9
- package/build/InlineFilesTransformer.js +16 -18
- package/build/StripStylesTransformer.js +14 -24
- package/build/TransformUtils.js +1 -1
- package/build/reflect-metadata.js +7 -7
- package/build/serializers/html-comment.js +8 -0
- package/build/serializers/index.js +6 -0
- package/build/serializers/ng-snapshot.js +59 -0
- package/build/serializers/no-ng-attributes.js +42 -0
- package/build/setup-jest.js +3 -3
- package/build/utils/ngcc-jest-processor.js +38 -0
- package/build/zone-patch/index.js +28 -68
- package/index.js +7 -0
- package/jest-preset.js +3 -3
- package/ngcc-jest-processor.js +1 -0
- package/package.json +60 -1
- package/setup-jest.js +1 -0
- package/AngularNoNgAttributesSnapshotSerializer.js +0 -57
- package/AngularSnapshotSerializer.js +0 -79
- package/HTMLCommentSerializer.js +0 -25
- package/zone-patch/README.md +0 -6
- package/zone-patch/index.js +0 -136
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
const { rootLogger } = require('ts-jest/dist/utils/logger');
|
|
3
|
+
rootLogger.warn("The snapshot serializer under import path `'jest-preset-angular/build/AngularSnapshotSerializer.js'` is deprecated and will be removed in v9.0.0. Please switch to `'jest-preset-angular/build/serializers/ng-snapshot'`");
|
|
4
|
+
const printAttributes = (val, attributes, print, indent, colors, opts) => {
|
|
3
5
|
return attributes
|
|
4
6
|
.sort()
|
|
5
|
-
.map(
|
|
7
|
+
.map((attribute) => {
|
|
6
8
|
return (opts.spacing +
|
|
7
9
|
indent(colors.prop.open + attribute + colors.prop.close + '=') +
|
|
8
10
|
colors.value.open +
|
|
9
11
|
(val.componentInstance[attribute] && val.componentInstance[attribute].constructor
|
|
10
12
|
? '{[Function ' + val.componentInstance[attribute].constructor.name + ']}'
|
|
11
|
-
: "
|
|
13
|
+
: `"${val.componentInstance[attribute]}"`) +
|
|
12
14
|
colors.value.close);
|
|
13
15
|
})
|
|
14
16
|
.join('');
|
|
15
17
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
const ivyEnabled = () => {
|
|
19
|
+
const { ɵivyEnabled } = require('@angular/core');
|
|
18
20
|
return !!ɵivyEnabled;
|
|
19
21
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const getComponentDef = (type) => type.ngComponentDef || type.ɵcmp;
|
|
23
|
+
const print = (fixture, print, indent, opts, colors) => {
|
|
24
|
+
let nodes = '';
|
|
25
|
+
let componentAttrs = '';
|
|
26
|
+
let componentName = '';
|
|
25
27
|
if (ivyEnabled()) {
|
|
26
|
-
|
|
28
|
+
const componentDef = getComponentDef(fixture.componentRef.componentType);
|
|
27
29
|
componentName = componentDef.selectors[0][0];
|
|
28
30
|
nodes = Array.from(fixture.componentRef.location.nativeElement.childNodes).map(print).join('');
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
31
33
|
componentName = fixture.componentRef._elDef.element.name;
|
|
32
34
|
nodes = (fixture.componentRef._view.nodes || [])
|
|
33
|
-
.filter(
|
|
34
|
-
.map(
|
|
35
|
+
.filter((node) => node && node.hasOwnProperty('renderElement'))
|
|
36
|
+
.map((node) => Array.from(node.renderElement.childNodes).map(print).join(''))
|
|
35
37
|
.join(opts.edgeSpacing);
|
|
36
38
|
}
|
|
37
|
-
|
|
39
|
+
const attributes = Object.keys(fixture.componentInstance);
|
|
38
40
|
if (attributes.length) {
|
|
39
41
|
componentAttrs += printAttributes(fixture, attributes, print, indent, colors, opts);
|
|
40
42
|
}
|
|
@@ -48,12 +50,10 @@ var print = function (fixture, print, indent, opts, colors) {
|
|
|
48
50
|
componentName +
|
|
49
51
|
'>');
|
|
50
52
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Object.prototype.hasOwnProperty.call(val, 'componentRef');
|
|
56
|
-
};
|
|
53
|
+
const test = (val) => val !== undefined &&
|
|
54
|
+
val !== null &&
|
|
55
|
+
typeof val === 'object' &&
|
|
56
|
+
Object.prototype.hasOwnProperty.call(val, 'componentRef');
|
|
57
57
|
module.exports = {
|
|
58
58
|
print: print,
|
|
59
59
|
test: test,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
const { rootLogger } = require('ts-jest/dist/utils/logger');
|
|
3
|
+
rootLogger.warn("The snapshot serializer under import path `'jest-preset-angular/build/HTMLCommentSerializer.js'` is deprecated and will be removed in v9.0.0. Please switch to `'jest-preset-angular/build/serializers/html-comment'`");
|
|
4
|
+
const HTML_ELEMENT_REGEXP = /Comment/;
|
|
5
|
+
const test = (value) => value !== undefined &&
|
|
6
|
+
value !== null &&
|
|
7
|
+
value.nodeType === 8 &&
|
|
8
|
+
value.constructor !== undefined &&
|
|
9
|
+
HTML_ELEMENT_REGEXP.test(value.constructor.name);
|
|
10
|
+
const print = () => '';
|
|
11
11
|
module.exports = {
|
|
12
12
|
print: print,
|
|
13
13
|
test: test,
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.factory = exports.version = exports.name = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const TransformUtils_1 = require("./TransformUtils");
|
|
5
|
+
const TEMPLATE_URL = 'templateUrl';
|
|
6
|
+
const STYLE_URLS = 'styleUrls';
|
|
7
|
+
const TEMPLATE = 'template';
|
|
8
|
+
const REQUIRE = 'require';
|
|
9
|
+
const TRANSFORM_PROPS = [TEMPLATE_URL, STYLE_URLS];
|
|
10
10
|
exports.name = 'angular-component-inline-files';
|
|
11
11
|
exports.version = 1;
|
|
12
12
|
function factory(cs) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const ts = cs.compilerModule;
|
|
14
|
+
const createStringLiteral = TransformUtils_1.getCreateStringLiteral(ts);
|
|
15
15
|
function isPropertyAssignmentToTransform(node) {
|
|
16
16
|
return ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && TRANSFORM_PROPS.includes(node.name.text);
|
|
17
17
|
}
|
|
18
18
|
function transfromPropertyAssignmentForJest(node) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const mutableAssignment = ts.getMutableClone(node);
|
|
20
|
+
const assignmentNameText = mutableAssignment.name.text;
|
|
21
21
|
switch (assignmentNameText) {
|
|
22
22
|
case TEMPLATE_URL:
|
|
23
|
-
|
|
23
|
+
let pathLiteral = mutableAssignment.initializer;
|
|
24
24
|
if (ts.isStringLiteral(pathLiteral)) {
|
|
25
25
|
if (pathLiteral.text && !pathLiteral.text.match(/^(\.\/|\.\.\/|\/)/)) {
|
|
26
|
-
pathLiteral = createStringLiteral(
|
|
26
|
+
pathLiteral = createStringLiteral(`./${pathLiteral.text}`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
const requireCall = ts.createCall(ts.createIdentifier(REQUIRE), undefined, [pathLiteral]);
|
|
30
30
|
mutableAssignment.name = ts.createIdentifier(TEMPLATE);
|
|
31
31
|
mutableAssignment.initializer = requireCall;
|
|
32
32
|
break;
|
|
@@ -39,8 +39,8 @@ function factory(cs) {
|
|
|
39
39
|
return mutableAssignment;
|
|
40
40
|
}
|
|
41
41
|
function createVisitor(ctx, _) {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const visitor = (node) => {
|
|
43
|
+
let resultNode = node;
|
|
44
44
|
if (isPropertyAssignmentToTransform(node)) {
|
|
45
45
|
resultNode = transfromPropertyAssignmentForJest(node);
|
|
46
46
|
}
|
|
@@ -49,8 +49,6 @@ function factory(cs) {
|
|
|
49
49
|
};
|
|
50
50
|
return visitor;
|
|
51
51
|
}
|
|
52
|
-
return
|
|
53
|
-
return ts.visitNode(sf, createVisitor(ctx, sf));
|
|
54
|
-
}; };
|
|
52
|
+
return (ctx) => (sf) => ts.visitNode(sf, createVisitor(ctx, sf));
|
|
55
53
|
}
|
|
56
54
|
exports.factory = factory;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.factory = exports.version = exports.name = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const STYLES = 'styles';
|
|
5
|
+
const COMPONENT = 'Component';
|
|
6
|
+
const TRANSFORM_IN_DECORATOR_PROPS = [STYLES];
|
|
7
7
|
exports.name = 'angular-component-strip-styles';
|
|
8
8
|
exports.version = 1;
|
|
9
9
|
function factory(cs) {
|
|
10
|
-
|
|
10
|
+
const ts = cs.compilerModule;
|
|
11
11
|
function isInDecoratorPropertyAssignmentToTransform(node) {
|
|
12
12
|
return getInDecoratorPropertyAssignmentsToTransform(node).length > 0;
|
|
13
13
|
}
|
|
@@ -16,25 +16,17 @@ function factory(cs) {
|
|
|
16
16
|
return [];
|
|
17
17
|
}
|
|
18
18
|
return node.decorators
|
|
19
|
-
.map(
|
|
19
|
+
.map((dec) => dec.expression)
|
|
20
20
|
.filter(ts.isCallExpression)
|
|
21
|
-
.filter(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
return Array.prototype.concat.apply(acc, nxtCallExpr.arguments.filter(ts.isObjectLiteralExpression).reduce(function (acc, nxtArg) {
|
|
26
|
-
return Array.prototype.concat.apply(acc, nxtArg.properties
|
|
27
|
-
.filter(ts.isPropertyAssignment)
|
|
28
|
-
.filter(function (propAss) {
|
|
29
|
-
return ts.isIdentifier(propAss.name) && TRANSFORM_IN_DECORATOR_PROPS.includes(propAss.name.text);
|
|
30
|
-
}));
|
|
31
|
-
}, []));
|
|
32
|
-
}, []);
|
|
21
|
+
.filter((callExpr) => ts.isIdentifier(callExpr.expression) && callExpr.expression.getText() === COMPONENT)
|
|
22
|
+
.reduce((acc, nxtCallExpr) => Array.prototype.concat.apply(acc, nxtCallExpr.arguments.filter(ts.isObjectLiteralExpression).reduce((acc, nxtArg) => Array.prototype.concat.apply(acc, nxtArg.properties
|
|
23
|
+
.filter(ts.isPropertyAssignment)
|
|
24
|
+
.filter((propAss) => ts.isIdentifier(propAss.name) && TRANSFORM_IN_DECORATOR_PROPS.includes(propAss.name.text))), [])), []);
|
|
33
25
|
}
|
|
34
26
|
function transformStylesAssignmentForJest(node) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
assignments.forEach(
|
|
27
|
+
const mutableNode = ts.getMutableClone(node);
|
|
28
|
+
const assignments = getInDecoratorPropertyAssignmentsToTransform(mutableNode);
|
|
29
|
+
assignments.forEach((assignment) => {
|
|
38
30
|
if (assignment.name.text === STYLES) {
|
|
39
31
|
assignment.initializer = ts.createArrayLiteral();
|
|
40
32
|
}
|
|
@@ -42,7 +34,7 @@ function factory(cs) {
|
|
|
42
34
|
return mutableNode;
|
|
43
35
|
}
|
|
44
36
|
function createVisitor(ctx, _) {
|
|
45
|
-
|
|
37
|
+
const visitor = (node) => {
|
|
46
38
|
if (isInDecoratorPropertyAssignmentToTransform(node)) {
|
|
47
39
|
return transformStylesAssignmentForJest(node);
|
|
48
40
|
}
|
|
@@ -52,8 +44,6 @@ function factory(cs) {
|
|
|
52
44
|
};
|
|
53
45
|
return visitor;
|
|
54
46
|
}
|
|
55
|
-
return
|
|
56
|
-
return ts.visitNode(sf, createVisitor(ctx, sf));
|
|
57
|
-
}; };
|
|
47
|
+
return (ctx) => (sf) => ts.visitNode(sf, createVisitor(ctx, sf));
|
|
58
48
|
}
|
|
59
49
|
exports.factory = factory;
|
package/build/TransformUtils.js
CHANGED
|
@@ -6,7 +6,7 @@ function getCreateStringLiteral(ts) {
|
|
|
6
6
|
return ts.createStringLiteral;
|
|
7
7
|
}
|
|
8
8
|
return function createStringLiteral(text) {
|
|
9
|
-
|
|
9
|
+
const node = ts.createNode(ts.SyntaxKind.StringLiteral, -1, -1);
|
|
10
10
|
node.text = text;
|
|
11
11
|
node.flags |= ts.NodeFlags.Synthesized;
|
|
12
12
|
return node;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const METADATA_KEY_PARAMTYPES = 'design:paramtypes';
|
|
3
|
+
const CTOR_PARAMETERS_JPA = 'ctorParametersJPA';
|
|
4
4
|
global.globalThis = global.globalThis || undefined;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const _global = globalThis || global;
|
|
6
|
+
const reflect = _global['Reflect'];
|
|
7
7
|
if (!reflect.metadata && !reflect.getOwnMetadata) {
|
|
8
|
-
reflect.metadata =
|
|
8
|
+
reflect.metadata = (metadataKey, metadataValue) => (target, key) => {
|
|
9
9
|
if (metadataKey === METADATA_KEY_PARAMTYPES && key === undefined) {
|
|
10
10
|
target[CTOR_PARAMETERS_JPA] = metadataValue;
|
|
11
11
|
}
|
|
12
|
-
};
|
|
13
|
-
reflect.getOwnMetadata =
|
|
12
|
+
};
|
|
13
|
+
reflect.getOwnMetadata = (metadata, target, key) => {
|
|
14
14
|
if (metadata === METADATA_KEY_PARAMTYPES && key === undefined) {
|
|
15
15
|
return target[CTOR_PARAMETERS_JPA];
|
|
16
16
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const HTML_ELEMENT_REGEXP = /Comment/;
|
|
3
|
+
const test = (value) => (value === null || value === void 0 ? void 0 : value.nodeType) === 8 && value.constructor !== undefined && HTML_ELEMENT_REGEXP.test(value.constructor.name);
|
|
4
|
+
const print = () => '';
|
|
5
|
+
module.exports = {
|
|
6
|
+
print,
|
|
7
|
+
test,
|
|
8
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const printAttributes = (val, attributes, _print, indent, colors, opts) => {
|
|
3
|
+
return attributes
|
|
4
|
+
.sort()
|
|
5
|
+
.map((attribute) => {
|
|
6
|
+
return (opts.spacing +
|
|
7
|
+
indent(`${colors.prop.open}${attribute}${colors.prop.close}=`) +
|
|
8
|
+
colors.value.open +
|
|
9
|
+
(val.componentInstance[attribute] && val.componentInstance[attribute].constructor
|
|
10
|
+
? `{[Function ${val.componentInstance[attribute].constructor.name}]}`
|
|
11
|
+
: `"${val.componentInstance[attribute]}"`) +
|
|
12
|
+
colors.value.close);
|
|
13
|
+
})
|
|
14
|
+
.join('');
|
|
15
|
+
};
|
|
16
|
+
const ivyEnabled = () => {
|
|
17
|
+
const { ɵivyEnabled } = require('@angular/core');
|
|
18
|
+
return !!ɵivyEnabled;
|
|
19
|
+
};
|
|
20
|
+
const getComponentDef = (type) => { var _a; return (_a = type.ngComponentDef) !== null && _a !== void 0 ? _a : type.ɵcmp; };
|
|
21
|
+
const print = (fixture, print, indent, opts, colors) => {
|
|
22
|
+
var _a;
|
|
23
|
+
let nodes = '';
|
|
24
|
+
let componentAttrs = '';
|
|
25
|
+
let componentName = '';
|
|
26
|
+
if (ivyEnabled()) {
|
|
27
|
+
const componentDef = getComponentDef(fixture.componentRef.componentType);
|
|
28
|
+
componentName = componentDef.selectors[0][0];
|
|
29
|
+
nodes = Array.from(fixture.componentRef.location.nativeElement.childNodes).map(print).join('');
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
componentName = (_a = fixture.componentRef._elDef.element) === null || _a === void 0 ? void 0 : _a.name;
|
|
33
|
+
nodes = (fixture.componentRef._view.nodes || [])
|
|
34
|
+
.filter((node) => node === null || node === void 0 ? void 0 : node.hasOwnProperty('renderElement'))
|
|
35
|
+
.map((node) => Array.from(node.renderElement.childNodes).map(print).join(''))
|
|
36
|
+
.join(opts.edgeSpacing);
|
|
37
|
+
}
|
|
38
|
+
const attributes = Object.keys(fixture.componentInstance);
|
|
39
|
+
if (attributes.length) {
|
|
40
|
+
componentAttrs += printAttributes(fixture, attributes, print, indent, colors, opts);
|
|
41
|
+
}
|
|
42
|
+
return ('<' +
|
|
43
|
+
componentName +
|
|
44
|
+
componentAttrs +
|
|
45
|
+
(componentAttrs.length ? '\n' : '') +
|
|
46
|
+
'>\n' +
|
|
47
|
+
indent(nodes) +
|
|
48
|
+
'\n</' +
|
|
49
|
+
componentName +
|
|
50
|
+
'>');
|
|
51
|
+
};
|
|
52
|
+
const test = (val) => val !== undefined &&
|
|
53
|
+
val !== null &&
|
|
54
|
+
typeof val === 'object' &&
|
|
55
|
+
Object.prototype.hasOwnProperty.call(val, 'componentRef');
|
|
56
|
+
module.exports = {
|
|
57
|
+
print,
|
|
58
|
+
test,
|
|
59
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const pretty_format_1 = require("pretty-format");
|
|
3
|
+
const jestDOMElementSerializer = pretty_format_1.plugins.DOMElement;
|
|
4
|
+
const attributesToRemovePatterns = ['ng-reflect', '_nghost', '_ngcontent', 'ng-version'];
|
|
5
|
+
const attributesToClean = {
|
|
6
|
+
class: [/^(?:mat|cdk|ng).*-\w*\d+-\d+$/, /^ng-star-inserted$/],
|
|
7
|
+
id: [/^(?:mat|cdk|ng).*-\d+$/],
|
|
8
|
+
for: [/^(?:mat|cdk|ng).*-\d+$/],
|
|
9
|
+
'aria-owns': [/^(?:mat|cdk|ng).*-\d+$/],
|
|
10
|
+
'aria-labelledby': [/^(?:mat|cdk|ng).*-\d+$/],
|
|
11
|
+
'aria-controls': [/^(?:mat|cdk|ng).*-\d+$/],
|
|
12
|
+
};
|
|
13
|
+
const hasAttributesToRemove = (attribute) => attributesToRemovePatterns.some((removePattern) => attribute.name.startsWith(removePattern));
|
|
14
|
+
const hasAttributesToClean = (attribute) => Object.keys(attributesToClean).some((removePatternKey) => attribute.name === removePatternKey);
|
|
15
|
+
const serialize = (node, ...rest) => {
|
|
16
|
+
const nodeCopy = node.cloneNode(true);
|
|
17
|
+
Object.values(nodeCopy.attributes)
|
|
18
|
+
.filter(hasAttributesToRemove)
|
|
19
|
+
.forEach((attribute) => nodeCopy.attributes.removeNamedItem(attribute.name));
|
|
20
|
+
Object.values(nodeCopy.attributes)
|
|
21
|
+
.filter(hasAttributesToClean)
|
|
22
|
+
.forEach((attribute) => {
|
|
23
|
+
attribute.value = attribute.value
|
|
24
|
+
.split(' ')
|
|
25
|
+
.filter((attrValue) => !attributesToClean[attribute.name].some((attributeCleanRegex) => attributeCleanRegex.test(attrValue)))
|
|
26
|
+
.join(' ');
|
|
27
|
+
if (attribute.value === '') {
|
|
28
|
+
nodeCopy.attributes.removeNamedItem(attribute.name);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
nodeCopy.attributes.setNamedItem(attribute);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return jestDOMElementSerializer.serialize(nodeCopy, ...rest);
|
|
35
|
+
};
|
|
36
|
+
const serializeTestFn = (val) => val.attributes !== undefined &&
|
|
37
|
+
Object.values(val.attributes).some((attribute) => hasAttributesToRemove(attribute) || hasAttributesToClean(attribute));
|
|
38
|
+
const test = (val) => jestDOMElementSerializer.test(val) && serializeTestFn(val);
|
|
39
|
+
module.exports = {
|
|
40
|
+
serialize,
|
|
41
|
+
test,
|
|
42
|
+
};
|
package/build/setup-jest.js
CHANGED
|
@@ -11,8 +11,8 @@ catch (err) {
|
|
|
11
11
|
require('zone.js/dist/fake-async-test');
|
|
12
12
|
require('./zone-patch');
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const getTestBed = require('@angular/core/testing').getTestBed;
|
|
15
|
+
const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
|
|
16
|
+
const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing')
|
|
17
17
|
.platformBrowserDynamicTesting;
|
|
18
18
|
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const IGNORE_ARGS = ['--clearCache', '--help', '--init', '--listTests', '--showConfig'];
|
|
8
|
+
const canRunNgcc = !process.argv.find((arg) => IGNORE_ARGS.includes(arg));
|
|
9
|
+
function findNodeModulesDirectory(startPoint) {
|
|
10
|
+
let current = startPoint;
|
|
11
|
+
while (path_1.dirname(current) !== current) {
|
|
12
|
+
const nodePath = path_1.join(current, 'node_modules');
|
|
13
|
+
if (fs_1.existsSync(nodePath)) {
|
|
14
|
+
return nodePath;
|
|
15
|
+
}
|
|
16
|
+
current = path_1.dirname(current);
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Cannot locate the 'node_modules' directory. Please make sure you are running jest from root level of your project`);
|
|
19
|
+
}
|
|
20
|
+
if (canRunNgcc) {
|
|
21
|
+
process.stdout.write('ngcc-jest-processor: running ngcc\n');
|
|
22
|
+
const { status, error } = child_process_1.spawnSync(process.execPath, [
|
|
23
|
+
require.resolve('@angular/compiler-cli/ngcc/main-ngcc.js'),
|
|
24
|
+
'--source',
|
|
25
|
+
findNodeModulesDirectory(process.cwd()),
|
|
26
|
+
'--properties',
|
|
27
|
+
...['es2015', 'main'],
|
|
28
|
+
'--first-only',
|
|
29
|
+
'false',
|
|
30
|
+
'--async',
|
|
31
|
+
], {
|
|
32
|
+
stdio: ['inherit', process.stderr, process.stderr],
|
|
33
|
+
});
|
|
34
|
+
if (status !== 0) {
|
|
35
|
+
const errorMessage = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : '';
|
|
36
|
+
throw new Error(`${errorMessage} NGCC failed ${errorMessage ? ', see above' : ''}.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -11,32 +11,28 @@ if (jest['__zone_patch__'] === true) {
|
|
|
11
11
|
throw new Error("'jest' has already been patched with 'Zone'.");
|
|
12
12
|
}
|
|
13
13
|
jest['__zone_patch__'] = true;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
|
|
15
|
+
const ProxyZoneSpec = Zone['ProxyZoneSpec'];
|
|
16
16
|
if (SyncTestZoneSpec === undefined) {
|
|
17
17
|
throw new Error('Missing: SyncTestZoneSpec (zone.js/dist/sync-test)');
|
|
18
18
|
}
|
|
19
19
|
if (ProxyZoneSpec === undefined) {
|
|
20
20
|
throw new Error('Missing: ProxyZoneSpec (zone.js/dist/proxy.js)');
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const env = global;
|
|
23
|
+
const ambientZone = Zone.current;
|
|
24
|
+
const syncZone = ambientZone.fork(new SyncTestZoneSpec('jest.describe'));
|
|
25
25
|
function wrapDescribeInZone(describeBody) {
|
|
26
|
-
return function () {
|
|
27
|
-
var args = [];
|
|
28
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
29
|
-
args[_i] = arguments[_i];
|
|
30
|
-
}
|
|
26
|
+
return function (...args) {
|
|
31
27
|
return syncZone.run(describeBody, null, args);
|
|
32
28
|
};
|
|
33
29
|
}
|
|
34
|
-
|
|
30
|
+
const testProxyZone = ambientZone.fork(new ProxyZoneSpec());
|
|
35
31
|
function wrapTestInZone(testBody) {
|
|
36
32
|
if (testBody === undefined) {
|
|
37
33
|
return;
|
|
38
34
|
}
|
|
39
|
-
|
|
35
|
+
const wrappedFunc = function () {
|
|
40
36
|
return testProxyZone.run(testBody, null, arguments);
|
|
41
37
|
};
|
|
42
38
|
try {
|
|
@@ -49,50 +45,26 @@ function wrapTestInZone(testBody) {
|
|
|
49
45
|
}
|
|
50
46
|
catch (e) {
|
|
51
47
|
return testBody.length === 0
|
|
52
|
-
?
|
|
53
|
-
:
|
|
48
|
+
? () => testProxyZone.run(testBody, null)
|
|
49
|
+
: (done) => testProxyZone.run(testBody, null, [done]);
|
|
54
50
|
}
|
|
55
51
|
return wrappedFunc;
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
return function () {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
eachArgs[_i] = arguments[_i];
|
|
62
|
-
}
|
|
63
|
-
return function () {
|
|
64
|
-
var args = [];
|
|
65
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
66
|
-
args[_i] = arguments[_i];
|
|
67
|
-
}
|
|
68
|
-
args[1] = wrapDescribeInZone(args[1]);
|
|
69
|
-
return originalJestFn.apply(this, eachArgs).apply(this, args);
|
|
70
|
-
};
|
|
53
|
+
const bindDescribe = (originalJestFn) => function (...eachArgs) {
|
|
54
|
+
return function (...args) {
|
|
55
|
+
args[1] = wrapDescribeInZone(args[1]);
|
|
56
|
+
return originalJestFn.apply(this, eachArgs).apply(this, args);
|
|
71
57
|
};
|
|
72
58
|
};
|
|
73
|
-
|
|
74
|
-
return function () {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
eachArgs[_i] = arguments[_i];
|
|
78
|
-
}
|
|
79
|
-
return function () {
|
|
80
|
-
var args = [];
|
|
81
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
82
|
-
args[_i] = arguments[_i];
|
|
83
|
-
}
|
|
84
|
-
args[1] = wrapTestInZone(args[1]);
|
|
85
|
-
return originalJestFn.apply(this, eachArgs).apply(this, args);
|
|
86
|
-
};
|
|
59
|
+
const bindTest = (originalJestFn) => function (...eachArgs) {
|
|
60
|
+
return function (...args) {
|
|
61
|
+
args[1] = wrapTestInZone(args[1]);
|
|
62
|
+
return originalJestFn.apply(this, eachArgs).apply(this, args);
|
|
87
63
|
};
|
|
88
64
|
};
|
|
89
|
-
['xdescribe', 'fdescribe', 'describe'].forEach(
|
|
90
|
-
|
|
91
|
-
env[methodName] = function () {
|
|
92
|
-
var args = [];
|
|
93
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
94
|
-
args[_i] = arguments[_i];
|
|
95
|
-
}
|
|
65
|
+
['xdescribe', 'fdescribe', 'describe'].forEach((methodName) => {
|
|
66
|
+
const originaljestFn = env[methodName];
|
|
67
|
+
env[methodName] = function (...args) {
|
|
96
68
|
args[1] = wrapDescribeInZone(args[1]);
|
|
97
69
|
return originaljestFn.apply(this, args);
|
|
98
70
|
};
|
|
@@ -102,13 +74,9 @@ var bindTest = function (originalJestFn) {
|
|
|
102
74
|
env[methodName].skip = env['xdescribe'];
|
|
103
75
|
}
|
|
104
76
|
});
|
|
105
|
-
['xit', 'fit', 'xtest', 'test', 'it'].forEach(
|
|
106
|
-
|
|
107
|
-
env[methodName] = function () {
|
|
108
|
-
var args = [];
|
|
109
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
110
|
-
args[_i] = arguments[_i];
|
|
111
|
-
}
|
|
77
|
+
['xit', 'fit', 'xtest', 'test', 'it'].forEach((methodName) => {
|
|
78
|
+
const originaljestFn = env[methodName];
|
|
79
|
+
env[methodName] = function (...args) {
|
|
112
80
|
args[1] = wrapTestInZone(args[1]);
|
|
113
81
|
return originaljestFn.apply(this, args);
|
|
114
82
|
};
|
|
@@ -116,22 +84,14 @@ var bindTest = function (originalJestFn) {
|
|
|
116
84
|
if (methodName === 'test' || methodName === 'it') {
|
|
117
85
|
env[methodName].only = env['fit'];
|
|
118
86
|
env[methodName].skip = env['xit'];
|
|
119
|
-
env[methodName].todo = function () {
|
|
120
|
-
var args = [];
|
|
121
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
122
|
-
args[_i] = arguments[_i];
|
|
123
|
-
}
|
|
87
|
+
env[methodName].todo = function (...args) {
|
|
124
88
|
return originaljestFn.todo.apply(this, args);
|
|
125
89
|
};
|
|
126
90
|
}
|
|
127
91
|
});
|
|
128
|
-
['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach(
|
|
129
|
-
|
|
130
|
-
env[methodName] = function () {
|
|
131
|
-
var args = [];
|
|
132
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
133
|
-
args[_i] = arguments[_i];
|
|
134
|
-
}
|
|
92
|
+
['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach((methodName) => {
|
|
93
|
+
const originaljestFn = env[methodName];
|
|
94
|
+
env[methodName] = function (...args) {
|
|
135
95
|
args[0] = wrapTestInZone(args[0]);
|
|
136
96
|
return originaljestFn.apply(this, args);
|
|
137
97
|
};
|
package/index.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
const { rootLogger } = require('ts-jest/dist/utils/logger');
|
|
2
|
+
|
|
3
|
+
rootLogger.warn(
|
|
4
|
+
"Import setup jest file via `import 'jest-preset-angular';` is deprecated and will be removed in v9.0.0." +
|
|
5
|
+
" Please switch to `import 'jest-preset-angular/setup-jest';`"
|
|
6
|
+
);
|
|
7
|
+
|
|
1
8
|
module.exports = require('./build/setup-jest.js');
|
package/jest-preset.js
CHANGED
|
@@ -23,8 +23,8 @@ module.exports = {
|
|
|
23
23
|
},
|
|
24
24
|
transformIgnorePatterns: ['node_modules/(?!@ngrx)'],
|
|
25
25
|
snapshotSerializers: [
|
|
26
|
-
'jest-preset-angular/build/
|
|
27
|
-
'jest-preset-angular/build/
|
|
28
|
-
'jest-preset-angular/build/
|
|
26
|
+
'jest-preset-angular/build/serializers/html-comment',
|
|
27
|
+
'jest-preset-angular/build/serializers/ng-snapshot',
|
|
28
|
+
'jest-preset-angular/build/serializers/no-ng-attributes',
|
|
29
29
|
],
|
|
30
30
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./build/utils/ngcc-jest-processor');
|