jest-preset-angular 8.2.1 → 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 +344 -128
- package/{LICENSE → LICENSE.md} +0 -0
- package/README.md +40 -458
- package/build/AngularNoNgAttributesSnapshotSerializer.js +18 -42
- package/build/AngularSnapshotSerializer.js +24 -38
- package/build/HTMLCommentSerializer.js +10 -18
- package/build/InlineFilesTransformer.js +21 -85
- package/build/StripStylesTransformer.js +14 -87
- package/build/TransformUtils.js +2 -7
- package/build/reflect-metadata.js +18 -0
- 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 +18 -0
- package/build/utils/ngcc-jest-processor.js +38 -0
- package/build/zone-patch/index.js +29 -84
- package/index.js +8 -1
- package/jest-preset.js +10 -8
- package/ngcc-jest-processor.js +1 -0
- package/package.json +63 -22
- package/setup-jest.js +1 -0
- package/.circleci/config.yml +0 -75
- package/.idea/jest-preset-angular.iml +0 -12
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -293
- package/build/reflectMetadata.js +0 -21
- package/build/setupJest.js +0 -12
- package/greenkeeper.json +0 -10
- package/tsconfig.json +0 -15
|
@@ -1,54 +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
|
-
(val.componentInstance[attribute] &&
|
|
10
|
-
val.componentInstance[attribute].constructor
|
|
11
|
-
|
|
12
|
-
val.componentInstance[attribute].constructor.name +
|
|
13
|
-
']}'
|
|
14
|
-
: "\"" + val.componentInstance[attribute] + "\"") +
|
|
11
|
+
(val.componentInstance[attribute] && val.componentInstance[attribute].constructor
|
|
12
|
+
? '{[Function ' + val.componentInstance[attribute].constructor.name + ']}'
|
|
13
|
+
: `"${val.componentInstance[attribute]}"`) +
|
|
15
14
|
colors.value.close);
|
|
16
15
|
})
|
|
17
16
|
.join('');
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// `Cannot resolve parameters...`.
|
|
22
|
-
var ɵivyEnabled = require('@angular/core').ɵivyEnabled;
|
|
18
|
+
const ivyEnabled = () => {
|
|
19
|
+
const { ɵivyEnabled } = require('@angular/core');
|
|
23
20
|
return !!ɵivyEnabled;
|
|
24
21
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var nodes = '';
|
|
31
|
-
var componentAttrs = '';
|
|
32
|
-
var componentName = '';
|
|
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 = '';
|
|
33
27
|
if (ivyEnabled()) {
|
|
34
|
-
|
|
28
|
+
const componentDef = getComponentDef(fixture.componentRef.componentType);
|
|
35
29
|
componentName = componentDef.selectors[0][0];
|
|
36
|
-
nodes = Array.from(fixture.componentRef.location.nativeElement.childNodes)
|
|
37
|
-
.map(print)
|
|
38
|
-
.join('');
|
|
30
|
+
nodes = Array.from(fixture.componentRef.location.nativeElement.childNodes).map(print).join('');
|
|
39
31
|
}
|
|
40
32
|
else {
|
|
41
33
|
componentName = fixture.componentRef._elDef.element.name;
|
|
42
34
|
nodes = (fixture.componentRef._view.nodes || [])
|
|
43
|
-
.filter(
|
|
44
|
-
.map(
|
|
45
|
-
return Array.from(node.renderElement.childNodes)
|
|
46
|
-
.map(print)
|
|
47
|
-
.join('');
|
|
48
|
-
})
|
|
35
|
+
.filter((node) => node && node.hasOwnProperty('renderElement'))
|
|
36
|
+
.map((node) => Array.from(node.renderElement.childNodes).map(print).join(''))
|
|
49
37
|
.join(opts.edgeSpacing);
|
|
50
38
|
}
|
|
51
|
-
|
|
39
|
+
const attributes = Object.keys(fixture.componentInstance);
|
|
52
40
|
if (attributes.length) {
|
|
53
41
|
componentAttrs += printAttributes(fixture, attributes, print, indent, colors, opts);
|
|
54
42
|
}
|
|
@@ -62,13 +50,11 @@ var print = function (fixture, print, indent, opts, colors) {
|
|
|
62
50
|
componentName +
|
|
63
51
|
'>');
|
|
64
52
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Object.prototype.hasOwnProperty.call(val, 'componentRef');
|
|
70
|
-
};
|
|
53
|
+
const test = (val) => val !== undefined &&
|
|
54
|
+
val !== null &&
|
|
55
|
+
typeof val === 'object' &&
|
|
56
|
+
Object.prototype.hasOwnProperty.call(val, 'componentRef');
|
|
71
57
|
module.exports = {
|
|
72
58
|
print: print,
|
|
73
|
-
test: test
|
|
59
|
+
test: test,
|
|
74
60
|
};
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the BSD-style license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
6
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
1
|
'use strict';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 = () => '';
|
|
19
11
|
module.exports = {
|
|
20
12
|
print: print,
|
|
21
|
-
test: test
|
|
13
|
+
test: test,
|
|
22
14
|
};
|
|
@@ -1,118 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Code is inspired by
|
|
4
|
-
* https://github.com/kulshekhar/ts-jest/blob/25e1c63dd3797793b0f46fa52fdee580b46f66ae/src/transformers/hoist-jest.ts
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var STYLE_URLS = 'styleUrls';
|
|
16
|
-
/** Angular component decorator Template property name */
|
|
17
|
-
var TEMPLATE = 'template';
|
|
18
|
-
/** Node require function name */
|
|
19
|
-
var REQUIRE = 'require';
|
|
20
|
-
/**
|
|
21
|
-
* Property names anywhere in an angular project to transform
|
|
22
|
-
*/
|
|
23
|
-
var TRANSFORM_PROPS = [TEMPLATE_URL, STYLE_URLS];
|
|
24
|
-
/**
|
|
25
|
-
* Transformer ID
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
3
|
+
exports.factory = exports.version = exports.name = void 0;
|
|
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];
|
|
28
10
|
exports.name = 'angular-component-inline-files';
|
|
29
|
-
// increment this each time the code is modified
|
|
30
|
-
/**
|
|
31
|
-
* Transformer Version
|
|
32
|
-
* @internal
|
|
33
|
-
*/
|
|
34
11
|
exports.version = 1;
|
|
35
|
-
/**
|
|
36
|
-
* The factory of hoisting transformer factory
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
12
|
function factory(cs) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*/
|
|
43
|
-
var ts = cs.compilerModule;
|
|
44
|
-
var createStringLiteral = TransformUtils_1.getCreateStringLiteral(ts);
|
|
45
|
-
/**
|
|
46
|
-
* Traverses the AST down to the relevant assignments anywhere in the file
|
|
47
|
-
* and returns a boolean indicating if it should be transformed.
|
|
48
|
-
*/
|
|
13
|
+
const ts = cs.compilerModule;
|
|
14
|
+
const createStringLiteral = TransformUtils_1.getCreateStringLiteral(ts);
|
|
49
15
|
function isPropertyAssignmentToTransform(node) {
|
|
50
|
-
return
|
|
51
|
-
ts.isIdentifier(node.name) &&
|
|
52
|
-
TRANSFORM_PROPS.includes(node.name.text));
|
|
16
|
+
return ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && TRANSFORM_PROPS.includes(node.name.text);
|
|
53
17
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Clones the assignment and manipulates it depending on its name.
|
|
56
|
-
* @param node the property assignment to change
|
|
57
|
-
*/
|
|
58
18
|
function transfromPropertyAssignmentForJest(node) {
|
|
59
|
-
|
|
60
|
-
|
|
19
|
+
const mutableAssignment = ts.getMutableClone(node);
|
|
20
|
+
const assignmentNameText = mutableAssignment.name.text;
|
|
61
21
|
switch (assignmentNameText) {
|
|
62
22
|
case TEMPLATE_URL:
|
|
63
|
-
|
|
64
|
-
// reuse the right-hand-side literal (the filepath) from the assignment
|
|
65
|
-
var pathLiteral = mutableAssignment.initializer;
|
|
66
|
-
// fix templatePathLiteral if it was a non-relative path
|
|
23
|
+
let pathLiteral = mutableAssignment.initializer;
|
|
67
24
|
if (ts.isStringLiteral(pathLiteral)) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
!pathLiteral.text.match(/^(\.\/|\.\.\/|\/)/)) {
|
|
71
|
-
// make path relative by prepending './'
|
|
72
|
-
pathLiteral = createStringLiteral("./" + pathLiteral.text);
|
|
25
|
+
if (pathLiteral.text && !pathLiteral.text.match(/^(\.\/|\.\.\/|\/)/)) {
|
|
26
|
+
pathLiteral = createStringLiteral(`./${pathLiteral.text}`);
|
|
73
27
|
}
|
|
74
28
|
}
|
|
75
|
-
|
|
76
|
-
var requireCall = ts.createCall(
|
|
77
|
-
/* expression */ ts.createIdentifier(REQUIRE),
|
|
78
|
-
/* type arguments */ undefined,
|
|
79
|
-
/* arguments array */ [pathLiteral]);
|
|
29
|
+
const requireCall = ts.createCall(ts.createIdentifier(REQUIRE), undefined, [pathLiteral]);
|
|
80
30
|
mutableAssignment.name = ts.createIdentifier(TEMPLATE);
|
|
81
31
|
mutableAssignment.initializer = requireCall;
|
|
82
32
|
break;
|
|
83
33
|
case STYLE_URLS:
|
|
84
|
-
// replace styleUrls value with emtpy array
|
|
85
|
-
// inlining all urls would be way more complicated and slower
|
|
86
34
|
mutableAssignment.initializer = ts.createArrayLiteral();
|
|
87
35
|
break;
|
|
36
|
+
default:
|
|
37
|
+
break;
|
|
88
38
|
}
|
|
89
39
|
return mutableAssignment;
|
|
90
40
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Create a source file visitor which will visit all nodes in a source file
|
|
93
|
-
* @param ctx The typescript transformation context
|
|
94
|
-
* @param _ The owning source file
|
|
95
|
-
*/
|
|
96
41
|
function createVisitor(ctx, _) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @param node The node to be visited
|
|
100
|
-
*/
|
|
101
|
-
var visitor = function (node) {
|
|
102
|
-
var resultNode = node;
|
|
103
|
-
// before we create a deep clone to modify, we make sure that
|
|
104
|
-
// this is an assignment which we want to transform
|
|
42
|
+
const visitor = (node) => {
|
|
43
|
+
let resultNode = node;
|
|
105
44
|
if (isPropertyAssignmentToTransform(node)) {
|
|
106
|
-
// get transformed node with changed properties
|
|
107
45
|
resultNode = transfromPropertyAssignmentForJest(node);
|
|
108
46
|
}
|
|
109
|
-
// look for interesting assignments inside this node in any case
|
|
110
47
|
resultNode = ts.visitEachChild(resultNode, visitor, ctx);
|
|
111
|
-
// finally return the currently visited node
|
|
112
48
|
return resultNode;
|
|
113
49
|
};
|
|
114
50
|
return visitor;
|
|
115
51
|
}
|
|
116
|
-
return
|
|
52
|
+
return (ctx) => (sf) => ts.visitNode(sf, createVisitor(ctx, sf));
|
|
117
53
|
}
|
|
118
54
|
exports.factory = factory;
|
|
@@ -1,122 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Code is inspired by
|
|
4
|
-
* https://github.com/kulshekhar/ts-jest/blob/25e1c63dd3797793b0f46fa52fdee580b46f66ae/src/transformers/hoist-jest.ts
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* IMPLEMENTATION DETAILS:
|
|
8
|
-
* This transformer handles one concern: removing styles.
|
|
9
|
-
*
|
|
10
|
-
* The property 'styles' inside a @Component(...) Decorator argument will
|
|
11
|
-
* be modified, even if they are not used in the context of an
|
|
12
|
-
* Angular Component.
|
|
13
|
-
*
|
|
14
|
-
* This is the required AST to trigger the transformation:
|
|
15
|
-
*
|
|
16
|
-
* ClassDeclaration
|
|
17
|
-
* Decorator
|
|
18
|
-
* CallExpression
|
|
19
|
-
* ObjectLiteralExpression
|
|
20
|
-
* PropertyAssignment
|
|
21
|
-
* Identifier
|
|
22
|
-
* StringLiteral
|
|
23
|
-
*/
|
|
24
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/** All props to be transformed inside a decorator */
|
|
30
|
-
var TRANSFORM_IN_DECORATOR_PROPS = [STYLES];
|
|
31
|
-
/**
|
|
32
|
-
* Transformer ID
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
3
|
+
exports.factory = exports.version = exports.name = void 0;
|
|
4
|
+
const STYLES = 'styles';
|
|
5
|
+
const COMPONENT = 'Component';
|
|
6
|
+
const TRANSFORM_IN_DECORATOR_PROPS = [STYLES];
|
|
35
7
|
exports.name = 'angular-component-strip-styles';
|
|
36
|
-
// increment this each time the code is modified
|
|
37
|
-
/**
|
|
38
|
-
* Transformer Version
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
8
|
exports.version = 1;
|
|
42
|
-
/**
|
|
43
|
-
* The factory of hoisting transformer factory
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
9
|
function factory(cs) {
|
|
47
|
-
|
|
48
|
-
* Our compiler (typescript, or a module with typescript-like interface)
|
|
49
|
-
*/
|
|
50
|
-
var ts = cs.compilerModule;
|
|
51
|
-
/**
|
|
52
|
-
* Traverses the AST down inside a decorator to a styles assignment
|
|
53
|
-
* and returns a boolean indicating if it should be transformed.
|
|
54
|
-
*/
|
|
10
|
+
const ts = cs.compilerModule;
|
|
55
11
|
function isInDecoratorPropertyAssignmentToTransform(node) {
|
|
56
12
|
return getInDecoratorPropertyAssignmentsToTransform(node).length > 0;
|
|
57
13
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Traverses the AST down inside a decorator to a styles assignment
|
|
60
|
-
* returns it in an array.
|
|
61
|
-
*/
|
|
62
14
|
function getInDecoratorPropertyAssignmentsToTransform(node) {
|
|
63
15
|
if (!ts.isClassDeclaration(node) || !node.decorators) {
|
|
64
16
|
return [];
|
|
65
17
|
}
|
|
66
18
|
return node.decorators
|
|
67
|
-
.map(
|
|
19
|
+
.map((dec) => dec.expression)
|
|
68
20
|
.filter(ts.isCallExpression)
|
|
69
|
-
.filter(
|
|
70
|
-
|
|
71
|
-
})
|
|
72
|
-
.reduce(function (acc, nxtCallExpr) { return Array.prototype.concat.apply(acc, nxtCallExpr.arguments
|
|
73
|
-
.filter(ts.isObjectLiteralExpression)
|
|
74
|
-
.reduce(function (acc, nxtArg) { return Array.prototype.concat.apply(acc, nxtArg.properties
|
|
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
|
|
75
23
|
.filter(ts.isPropertyAssignment)
|
|
76
|
-
.filter(
|
|
77
|
-
return ts.isIdentifier(propAss.name) &&
|
|
78
|
-
TRANSFORM_IN_DECORATOR_PROPS.includes(propAss.name.text);
|
|
79
|
-
})); }, [])); }, []);
|
|
24
|
+
.filter((propAss) => ts.isIdentifier(propAss.name) && TRANSFORM_IN_DECORATOR_PROPS.includes(propAss.name.text))), [])), []);
|
|
80
25
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Clones the styles assignment and manipulates it.
|
|
83
|
-
* @param node the property assignment to change
|
|
84
|
-
*/
|
|
85
26
|
function transformStylesAssignmentForJest(node) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
assignments.forEach(
|
|
27
|
+
const mutableNode = ts.getMutableClone(node);
|
|
28
|
+
const assignments = getInDecoratorPropertyAssignmentsToTransform(mutableNode);
|
|
29
|
+
assignments.forEach((assignment) => {
|
|
89
30
|
if (assignment.name.text === STYLES) {
|
|
90
|
-
// replace initializer array with empty array
|
|
91
31
|
assignment.initializer = ts.createArrayLiteral();
|
|
92
32
|
}
|
|
93
33
|
});
|
|
94
34
|
return mutableNode;
|
|
95
35
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Create a source file visitor which will visit all nodes in a source file
|
|
98
|
-
* @param ctx The typescript transformation context
|
|
99
|
-
* @param _ The owning source file
|
|
100
|
-
*/
|
|
101
36
|
function createVisitor(ctx, _) {
|
|
102
|
-
|
|
103
|
-
* Main visitor, which will be called recursively for each node in the source file's AST
|
|
104
|
-
* @param node The node to be visited
|
|
105
|
-
*/
|
|
106
|
-
var visitor = function (node) {
|
|
107
|
-
// before we create a deep clone to modify, we make sure that
|
|
108
|
-
// this is an assignment which we want to transform
|
|
37
|
+
const visitor = (node) => {
|
|
109
38
|
if (isInDecoratorPropertyAssignmentToTransform(node)) {
|
|
110
|
-
// get transformed node with changed properties
|
|
111
39
|
return transformStylesAssignmentForJest(node);
|
|
112
40
|
}
|
|
113
41
|
else {
|
|
114
|
-
// else look for assignments inside this node recursively
|
|
115
42
|
return ts.visitEachChild(node, visitor, ctx);
|
|
116
43
|
}
|
|
117
44
|
};
|
|
118
45
|
return visitor;
|
|
119
46
|
}
|
|
120
|
-
return
|
|
47
|
+
return (ctx) => (sf) => ts.visitNode(sf, createVisitor(ctx, sf));
|
|
121
48
|
}
|
|
122
49
|
exports.factory = factory;
|
package/build/TransformUtils.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
* returns the compiler function to create a string literal. If an old version
|
|
5
|
-
* of the TypeScript module is used, it will create a function that replaces the
|
|
6
|
-
* behavior of the `createStringLiteral` function.
|
|
7
|
-
* @param ts TypeScript compiler module
|
|
8
|
-
*/
|
|
3
|
+
exports.getCreateStringLiteral = void 0;
|
|
9
4
|
function getCreateStringLiteral(ts) {
|
|
10
5
|
if (ts.createStringLiteral && typeof ts.createStringLiteral === 'function') {
|
|
11
6
|
return ts.createStringLiteral;
|
|
12
7
|
}
|
|
13
8
|
return function createStringLiteral(text) {
|
|
14
|
-
|
|
9
|
+
const node = ts.createNode(ts.SyntaxKind.StringLiteral, -1, -1);
|
|
15
10
|
node.text = text;
|
|
16
11
|
node.flags |= ts.NodeFlags.Synthesized;
|
|
17
12
|
return node;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const METADATA_KEY_PARAMTYPES = 'design:paramtypes';
|
|
3
|
+
const CTOR_PARAMETERS_JPA = 'ctorParametersJPA';
|
|
4
|
+
global.globalThis = global.globalThis || undefined;
|
|
5
|
+
const _global = globalThis || global;
|
|
6
|
+
const reflect = _global['Reflect'];
|
|
7
|
+
if (!reflect.metadata && !reflect.getOwnMetadata) {
|
|
8
|
+
reflect.metadata = (metadataKey, metadataValue) => (target, key) => {
|
|
9
|
+
if (metadataKey === METADATA_KEY_PARAMTYPES && key === undefined) {
|
|
10
|
+
target[CTOR_PARAMETERS_JPA] = metadataValue;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
reflect.getOwnMetadata = (metadata, target, key) => {
|
|
14
|
+
if (metadata === METADATA_KEY_PARAMTYPES && key === undefined) {
|
|
15
|
+
return target[CTOR_PARAMETERS_JPA];
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
require('./reflect-metadata');
|
|
3
|
+
try {
|
|
4
|
+
require('zone.js/bundles/zone-testing-bundle.umd.js');
|
|
5
|
+
}
|
|
6
|
+
catch (err) {
|
|
7
|
+
require('zone.js/dist/zone');
|
|
8
|
+
require('zone.js/dist/proxy');
|
|
9
|
+
require('zone.js/dist/sync-test');
|
|
10
|
+
require('zone.js/dist/async-test');
|
|
11
|
+
require('zone.js/dist/fake-async-test');
|
|
12
|
+
require('./zone-patch');
|
|
13
|
+
}
|
|
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
|
+
.platformBrowserDynamicTesting;
|
|
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
|
+
}
|