jest-preset-angular 7.0.0 → 8.0.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/.circleci/config.yml +10 -8
- package/.vscode/launch.json +36 -0
- package/CHANGELOG.md +31 -3
- package/README.md +48 -21
- package/build/AngularNoNgAttributesSnapshotSerializer.js +36 -0
- package/build/AngularSnapshotSerializer.js +49 -0
- package/{HTMLCommentSerializer.js → build/HTMLCommentSerializer.js} +11 -14
- package/{InlineHtmlStripStylesTransformer.js → build/InlineFilesTransformer.js} +31 -32
- package/build/StripStylesTransformer.js +122 -0
- package/build/TransformUtils.js +20 -0
- package/build/reflectMetadata.js +21 -0
- package/build/setupJest.js +12 -0
- package/build/zone-patch/index.js +95 -0
- package/greenkeeper.json +10 -0
- package/index.js +1 -1
- package/jest-preset.js +9 -5
- package/package.json +8 -6
- package/tsconfig.json +2 -2
- package/yarn-error.log +3628 -0
- package/AngularSnapshotSerializer.js +0 -67
- package/setupJest.js +0 -19
- package/zone-patch/LICENSE +0 -29
- package/zone-patch/README.md +0 -6
- package/zone-patch/index.js +0 -108
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const printAttributes = (val, attributes, print, indent, colors, opts) => {
|
|
4
|
-
return attributes
|
|
5
|
-
.sort()
|
|
6
|
-
.map(attribute => {
|
|
7
|
-
return (
|
|
8
|
-
opts.spacing +
|
|
9
|
-
indent(colors.prop.open + attribute + colors.prop.close + '=') +
|
|
10
|
-
colors.value.open +
|
|
11
|
-
(val.componentInstance[attribute] &&
|
|
12
|
-
val.componentInstance[attribute].constructor
|
|
13
|
-
? '{[Function ' +
|
|
14
|
-
val.componentInstance[attribute].constructor.name +
|
|
15
|
-
']}'
|
|
16
|
-
: `"${val.componentInstance[attribute]}"`) +
|
|
17
|
-
colors.value.close
|
|
18
|
-
);
|
|
19
|
-
})
|
|
20
|
-
.join('');
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const print = (val, print, indent, opts, colors) => {
|
|
24
|
-
let componentAttrs = '';
|
|
25
|
-
|
|
26
|
-
const componentName = val.componentRef._elDef.element.name;
|
|
27
|
-
const nodes = (val.componentRef._view.nodes || [])
|
|
28
|
-
.filter(node => node && node.hasOwnProperty('renderElement'))
|
|
29
|
-
.map(node => Array.from(node.renderElement.childNodes).map(print).join(''))
|
|
30
|
-
.join(opts.edgeSpacing);
|
|
31
|
-
|
|
32
|
-
const attributes = Object.keys(val.componentInstance);
|
|
33
|
-
|
|
34
|
-
if (attributes.length) {
|
|
35
|
-
componentAttrs += printAttributes(
|
|
36
|
-
val,
|
|
37
|
-
attributes,
|
|
38
|
-
print,
|
|
39
|
-
indent,
|
|
40
|
-
colors,
|
|
41
|
-
opts
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
'<' +
|
|
47
|
-
componentName +
|
|
48
|
-
componentAttrs +
|
|
49
|
-
(componentAttrs.length ? '\n' : '') +
|
|
50
|
-
'>\n' +
|
|
51
|
-
indent(nodes) +
|
|
52
|
-
'\n</' +
|
|
53
|
-
componentName +
|
|
54
|
-
'>'
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const test = val =>
|
|
59
|
-
val !== undefined &&
|
|
60
|
-
val !== null &&
|
|
61
|
-
typeof val === 'object' &&
|
|
62
|
-
Object.prototype.hasOwnProperty.call(val, 'componentRef');
|
|
63
|
-
|
|
64
|
-
module.exports = {
|
|
65
|
-
print: print,
|
|
66
|
-
test: test
|
|
67
|
-
};
|
package/setupJest.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('core-js/es6/reflect');
|
|
4
|
-
require('core-js/es7/reflect');
|
|
5
|
-
require('zone.js/dist/zone.js');
|
|
6
|
-
require('zone.js/dist/proxy.js');
|
|
7
|
-
require('zone.js/dist/sync-test');
|
|
8
|
-
require('zone.js/dist/async-test');
|
|
9
|
-
require('zone.js/dist/fake-async-test');
|
|
10
|
-
require('./zone-patch');
|
|
11
|
-
|
|
12
|
-
const getTestBed = require('@angular/core/testing').getTestBed;
|
|
13
|
-
const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule;
|
|
14
|
-
const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting;
|
|
15
|
-
|
|
16
|
-
getTestBed().initTestEnvironment(
|
|
17
|
-
BrowserDynamicTestingModule,
|
|
18
|
-
platformBrowserDynamicTesting()
|
|
19
|
-
);
|
package/zone-patch/LICENSE
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
BSD 3-Clause License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017, Michał Pierzchała
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions are met:
|
|
8
|
-
|
|
9
|
-
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
-
list of conditions and the following disclaimer.
|
|
11
|
-
|
|
12
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
-
this list of conditions and the following disclaimer in the documentation
|
|
14
|
-
and/or other materials provided with the distribution.
|
|
15
|
-
|
|
16
|
-
* Neither the name of the copyright holder nor the names of its
|
|
17
|
-
contributors may be used to endorse or promote products derived from
|
|
18
|
-
this software without specific prior written permission.
|
|
19
|
-
|
|
20
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/zone-patch/README.md
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# zone-patch
|
|
2
|
-
Enables Jest functions to be run within Zone.js context, specifically for [Angular](https://angular.io) apps.
|
|
3
|
-
|
|
4
|
-
It's crucial to run this patch here, because at this point patched functions like `test` or `describe` are available in global scope.
|
|
5
|
-
|
|
6
|
-
`zone-patch` has been included in `setupJest.js` by default.
|
package/zone-patch/index.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Patch Jest's describe/test/beforeEach/afterEach functions so test code
|
|
3
|
-
* always runs in a testZone (ProxyZone).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
if (Zone === undefined) {
|
|
7
|
-
throw new Error('Missing: Zone (zone.js)');
|
|
8
|
-
}
|
|
9
|
-
if (jest === undefined) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
'Missing: jest.\n' +
|
|
12
|
-
'This patch must be included in a script called with ' +
|
|
13
|
-
'`setupTestFrameworkScriptFile` in Jest config.'
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
if (jest['__zone_patch__'] === true) {
|
|
17
|
-
throw new Error("'jest' has already been patched with 'Zone'.");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
jest['__zone_patch__'] = true;
|
|
21
|
-
const SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
|
|
22
|
-
const ProxyZoneSpec = Zone['ProxyZoneSpec'];
|
|
23
|
-
|
|
24
|
-
if (SyncTestZoneSpec === undefined) {
|
|
25
|
-
throw new Error('Missing: SyncTestZoneSpec (zone.js/dist/sync-test)');
|
|
26
|
-
}
|
|
27
|
-
if (ProxyZoneSpec === undefined) {
|
|
28
|
-
throw new Error('Missing: ProxyZoneSpec (zone.js/dist/proxy.js)');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const env = global;
|
|
32
|
-
const ambientZone = Zone.current;
|
|
33
|
-
|
|
34
|
-
// Create a synchronous-only zone in which to run `describe` blocks in order to
|
|
35
|
-
// raise an error if any asynchronous operations are attempted
|
|
36
|
-
// inside of a `describe` but outside of a `beforeEach` or `it`.
|
|
37
|
-
const syncZone = ambientZone.fork(new SyncTestZoneSpec('jest.describe'));
|
|
38
|
-
function wrapDescribeInZone(describeBody) {
|
|
39
|
-
return function() {
|
|
40
|
-
return syncZone.run(describeBody, null, arguments);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Create a proxy zone in which to run `test` blocks so that the tests function
|
|
45
|
-
// can retroactively install different zones.
|
|
46
|
-
const testProxyZone = ambientZone.fork(new ProxyZoneSpec());
|
|
47
|
-
function wrapTestInZone(testBody) {
|
|
48
|
-
if (testBody === undefined) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
return testBody.length === 0
|
|
52
|
-
? () => testProxyZone.run(testBody, null)
|
|
53
|
-
: done => testProxyZone.run(testBody, null, [done]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const bindDescribe = originalJestFn =>
|
|
57
|
-
function() {
|
|
58
|
-
const eachArguments = arguments;
|
|
59
|
-
return function(description, specDefinitions, timeout) {
|
|
60
|
-
arguments[1] = wrapDescribeInZone(specDefinitions);
|
|
61
|
-
return originalJestFn.apply(this, eachArguments).apply(this, arguments);
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
['xdescribe', 'fdescribe', 'describe'].forEach(methodName => {
|
|
66
|
-
const originaljestFn = env[methodName];
|
|
67
|
-
env[methodName] = function(description, specDefinitions, timeout) {
|
|
68
|
-
arguments[1] = wrapDescribeInZone(specDefinitions);
|
|
69
|
-
return originaljestFn.apply(this, arguments);
|
|
70
|
-
};
|
|
71
|
-
env[methodName].each = bindDescribe(originaljestFn.each);
|
|
72
|
-
if (methodName === 'describe') {
|
|
73
|
-
env[methodName].only = env['fdescribe'];
|
|
74
|
-
env[methodName].skip = env['xdescribe'];
|
|
75
|
-
env[methodName].only.each = bindDescribe(originaljestFn.only.each);
|
|
76
|
-
env[methodName].skip.each = bindDescribe(originaljestFn.skip.each);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
['xit', 'fit', 'xtest', 'test', 'it'].forEach(methodName => {
|
|
81
|
-
const originaljestFn = env[methodName];
|
|
82
|
-
env[methodName] = function(description, specDefinitions, timeout) {
|
|
83
|
-
arguments[1] = wrapTestInZone(specDefinitions);
|
|
84
|
-
return originaljestFn.apply(this, arguments);
|
|
85
|
-
};
|
|
86
|
-
// The revised method will be populated to the final each method, so we only declare the method that in the new globals
|
|
87
|
-
env[methodName].each = originaljestFn.each;
|
|
88
|
-
|
|
89
|
-
if (methodName === 'test' || methodName === 'it') {
|
|
90
|
-
env[methodName].only = env['fit'];
|
|
91
|
-
env[methodName].only.each = originaljestFn.only.each;
|
|
92
|
-
|
|
93
|
-
env[methodName].skip = env['xit'];
|
|
94
|
-
env[methodName].skip.each = originaljestFn.skip.each;
|
|
95
|
-
|
|
96
|
-
env[methodName].todo = function(description) {
|
|
97
|
-
return originaljestFn.todo.apply(this, arguments);
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach(methodName => {
|
|
103
|
-
const originaljestFn = env[methodName];
|
|
104
|
-
env[methodName] = function(specDefinitions, timeout) {
|
|
105
|
-
arguments[0] = wrapTestInZone(specDefinitions);
|
|
106
|
-
return originaljestFn.apply(this, arguments);
|
|
107
|
-
};
|
|
108
|
-
});
|