1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _expect = require('expect');
|
9 |
|
10 | var _jestSnapshot = require('jest-snapshot');
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const addSuppressedErrors = result => {
|
22 | const {suppressedErrors} = (0, _expect.getState)();
|
23 | (0, _expect.setState)({
|
24 | suppressedErrors: []
|
25 | });
|
26 |
|
27 | if (suppressedErrors.length) {
|
28 | result.status = 'failed';
|
29 | result.failedExpectations = suppressedErrors.map(error => ({
|
30 | actual: '',
|
31 |
|
32 | error,
|
33 | expected: '',
|
34 | matcherName: '',
|
35 | message: error.message,
|
36 | passed: false,
|
37 | stack: error.stack
|
38 | }));
|
39 | }
|
40 | };
|
41 |
|
42 | const addAssertionErrors = result => {
|
43 | const assertionErrors = (0, _expect.extractExpectedAssertionsErrors)();
|
44 |
|
45 | if (assertionErrors.length) {
|
46 | const jasmineErrors = assertionErrors.map(({actual, error, expected}) => ({
|
47 | actual,
|
48 | expected,
|
49 | message: error.stack,
|
50 | passed: false
|
51 | }));
|
52 | result.status = 'failed';
|
53 | result.failedExpectations = result.failedExpectations.concat(jasmineErrors);
|
54 | }
|
55 | };
|
56 |
|
57 | const patchJasmine = () => {
|
58 | global.jasmine.Spec = (realSpec => {
|
59 | class Spec extends realSpec {
|
60 | constructor(attr) {
|
61 | const resultCallback = attr.resultCallback;
|
62 |
|
63 | attr.resultCallback = function (result) {
|
64 | addSuppressedErrors(result);
|
65 | addAssertionErrors(result);
|
66 | resultCallback.call(attr, result);
|
67 | };
|
68 |
|
69 | const onStart = attr.onStart;
|
70 |
|
71 | attr.onStart = context => {
|
72 | (0, _expect.setState)({
|
73 | currentTestName: context.getFullName()
|
74 | });
|
75 | onStart && onStart.call(attr, context);
|
76 | };
|
77 |
|
78 | super(attr);
|
79 | }
|
80 | }
|
81 |
|
82 | return Spec;
|
83 | })(global.jasmine.Spec);
|
84 | };
|
85 |
|
86 | var _default = async ({config, globalConfig, localRequire, testPath}) => {
|
87 |
|
88 |
|
89 | config.snapshotSerializers
|
90 | .concat()
|
91 | .reverse()
|
92 | .forEach(path => {
|
93 | (0, _jestSnapshot.addSerializer)(localRequire(path));
|
94 | });
|
95 | patchJasmine();
|
96 | const {expand, updateSnapshot} = globalConfig;
|
97 | const {prettierPath, snapshotFormat} = config;
|
98 | const snapshotResolver = await (0, _jestSnapshot.buildSnapshotResolver)(
|
99 | config,
|
100 | localRequire
|
101 | );
|
102 | const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
|
103 | const snapshotState = new _jestSnapshot.SnapshotState(snapshotPath, {
|
104 | expand,
|
105 | prettierPath,
|
106 | snapshotFormat,
|
107 | updateSnapshot
|
108 | });
|
109 |
|
110 | (0, _expect.setState)({
|
111 | snapshotState,
|
112 | testPath
|
113 | });
|
114 |
|
115 | return snapshotState;
|
116 | };
|
117 |
|
118 | exports.default = _default;
|