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.
@@ -1,8 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * Patch Jest's describe/test/beforeEach/afterEach functions so test code
4
- * always runs in a testZone (ProxyZone).
5
- */
6
2
  if (Zone === undefined) {
7
3
  throw new Error('Missing: Zone (zone.js)');
8
4
  }
@@ -15,99 +11,60 @@ if (jest['__zone_patch__'] === true) {
15
11
  throw new Error("'jest' has already been patched with 'Zone'.");
16
12
  }
17
13
  jest['__zone_patch__'] = true;
18
- var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
19
- var ProxyZoneSpec = Zone['ProxyZoneSpec'];
14
+ const SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
15
+ const ProxyZoneSpec = Zone['ProxyZoneSpec'];
20
16
  if (SyncTestZoneSpec === undefined) {
21
17
  throw new Error('Missing: SyncTestZoneSpec (zone.js/dist/sync-test)');
22
18
  }
23
19
  if (ProxyZoneSpec === undefined) {
24
20
  throw new Error('Missing: ProxyZoneSpec (zone.js/dist/proxy.js)');
25
21
  }
26
- var env = global;
27
- var ambientZone = Zone.current;
28
- // Create a synchronous-only zone in which to run `describe` blocks in order to
29
- // raise an error if any asynchronous operations are attempted
30
- // inside of a `describe` but outside of a `beforeEach` or `it`.
31
- var syncZone = ambientZone.fork(new SyncTestZoneSpec('jest.describe'));
22
+ const env = global;
23
+ const ambientZone = Zone.current;
24
+ const syncZone = ambientZone.fork(new SyncTestZoneSpec('jest.describe'));
32
25
  function wrapDescribeInZone(describeBody) {
33
- return function () {
34
- var args = [];
35
- for (var _i = 0; _i < arguments.length; _i++) {
36
- args[_i] = arguments[_i];
37
- }
26
+ return function (...args) {
38
27
  return syncZone.run(describeBody, null, args);
39
28
  };
40
29
  }
41
- // Create a proxy zone in which to run `test` blocks so that the tests function
42
- // can retroactively install different zones.
43
- var testProxyZone = ambientZone.fork(new ProxyZoneSpec());
30
+ const testProxyZone = ambientZone.fork(new ProxyZoneSpec());
44
31
  function wrapTestInZone(testBody) {
45
32
  if (testBody === undefined) {
46
33
  return;
47
34
  }
48
- var wrappedFunc = function () {
35
+ const wrappedFunc = function () {
49
36
  return testProxyZone.run(testBody, null, arguments);
50
37
  };
51
38
  try {
52
39
  Object.defineProperty(wrappedFunc, 'length', {
53
40
  configurable: true,
54
41
  writable: true,
55
- enumerable: false
42
+ enumerable: false,
56
43
  });
57
44
  wrappedFunc.length = testBody.length;
58
45
  }
59
46
  catch (e) {
60
47
  return testBody.length === 0
61
- ? function () { return testProxyZone.run(testBody, null); }
62
- : function (done) { return testProxyZone.run(testBody, null, [done]); };
48
+ ? () => testProxyZone.run(testBody, null)
49
+ : (done) => testProxyZone.run(testBody, null, [done]);
63
50
  }
64
51
  return wrappedFunc;
65
52
  }
66
- /**
67
- * bind describe method to wrap describe.each function
68
- */
69
- var bindDescribe = function (originalJestFn) {
70
- return function () {
71
- var eachArgs = [];
72
- for (var _i = 0; _i < arguments.length; _i++) {
73
- eachArgs[_i] = arguments[_i];
74
- }
75
- return function () {
76
- var args = [];
77
- for (var _i = 0; _i < arguments.length; _i++) {
78
- args[_i] = arguments[_i];
79
- }
80
- args[1] = wrapDescribeInZone(args[1]);
81
- return originalJestFn.apply(this, eachArgs).apply(this, args);
82
- };
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);
83
57
  };
84
58
  };
85
- /**
86
- * bind test method to wrap test.each function
87
- */
88
- var bindTest = function (originalJestFn) {
89
- return function () {
90
- var eachArgs = [];
91
- for (var _i = 0; _i < arguments.length; _i++) {
92
- eachArgs[_i] = arguments[_i];
93
- }
94
- return function () {
95
- var args = [];
96
- for (var _i = 0; _i < arguments.length; _i++) {
97
- args[_i] = arguments[_i];
98
- }
99
- args[1] = wrapTestInZone(args[1]);
100
- return originalJestFn.apply(this, eachArgs).apply(this, args);
101
- };
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);
102
63
  };
103
64
  };
104
- ['xdescribe', 'fdescribe', 'describe'].forEach(function (methodName) {
105
- var originaljestFn = env[methodName];
106
- env[methodName] = function () {
107
- var args = [];
108
- for (var _i = 0; _i < arguments.length; _i++) {
109
- args[_i] = arguments[_i];
110
- }
65
+ ['xdescribe', 'fdescribe', 'describe'].forEach((methodName) => {
66
+ const originaljestFn = env[methodName];
67
+ env[methodName] = function (...args) {
111
68
  args[1] = wrapDescribeInZone(args[1]);
112
69
  return originaljestFn.apply(this, args);
113
70
  };
@@ -117,13 +74,9 @@ var bindTest = function (originalJestFn) {
117
74
  env[methodName].skip = env['xdescribe'];
118
75
  }
119
76
  });
120
- ['xit', 'fit', 'xtest', 'test', 'it'].forEach(function (methodName) {
121
- var originaljestFn = env[methodName];
122
- env[methodName] = function () {
123
- var args = [];
124
- for (var _i = 0; _i < arguments.length; _i++) {
125
- args[_i] = arguments[_i];
126
- }
77
+ ['xit', 'fit', 'xtest', 'test', 'it'].forEach((methodName) => {
78
+ const originaljestFn = env[methodName];
79
+ env[methodName] = function (...args) {
127
80
  args[1] = wrapTestInZone(args[1]);
128
81
  return originaljestFn.apply(this, args);
129
82
  };
@@ -131,22 +84,14 @@ var bindTest = function (originalJestFn) {
131
84
  if (methodName === 'test' || methodName === 'it') {
132
85
  env[methodName].only = env['fit'];
133
86
  env[methodName].skip = env['xit'];
134
- env[methodName].todo = function () {
135
- var args = [];
136
- for (var _i = 0; _i < arguments.length; _i++) {
137
- args[_i] = arguments[_i];
138
- }
87
+ env[methodName].todo = function (...args) {
139
88
  return originaljestFn.todo.apply(this, args);
140
89
  };
141
90
  }
142
91
  });
143
- ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach(function (methodName) {
144
- var originaljestFn = env[methodName];
145
- env[methodName] = function () {
146
- var args = [];
147
- for (var _i = 0; _i < arguments.length; _i++) {
148
- args[_i] = arguments[_i];
149
- }
92
+ ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach((methodName) => {
93
+ const originaljestFn = env[methodName];
94
+ env[methodName] = function (...args) {
150
95
  args[0] = wrapTestInZone(args[0]);
151
96
  return originaljestFn.apply(this, args);
152
97
  };
package/index.js CHANGED
@@ -1 +1,8 @@
1
- module.exports = require('./build/setupJest.js');
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
+
8
+ module.exports = require('./build/setup-jest.js');
package/jest-preset.js CHANGED
@@ -1,12 +1,14 @@
1
1
  module.exports = {
2
2
  globals: {
3
3
  'ts-jest': {
4
- tsConfig: '<rootDir>/tsconfig.spec.json',
4
+ tsconfig: '<rootDir>/tsconfig.spec.json',
5
5
  stringifyContentPathRegex: '\\.html$',
6
- astTransformers: [
7
- 'jest-preset-angular/build/InlineFilesTransformer',
8
- 'jest-preset-angular/build/StripStylesTransformer',
9
- ],
6
+ astTransformers: {
7
+ before: [
8
+ 'jest-preset-angular/build/InlineFilesTransformer',
9
+ 'jest-preset-angular/build/StripStylesTransformer',
10
+ ],
11
+ },
10
12
  },
11
13
  },
12
14
  transform: {
@@ -21,8 +23,8 @@ module.exports = {
21
23
  },
22
24
  transformIgnorePatterns: ['node_modules/(?!@ngrx)'],
23
25
  snapshotSerializers: [
24
- 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
25
- 'jest-preset-angular/build/AngularSnapshotSerializer.js',
26
- 'jest-preset-angular/build/HTMLCommentSerializer.js',
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',
27
29
  ],
28
30
  };
@@ -0,0 +1 @@
1
+ module.exports = require('./build/utils/ngcc-jest-processor');
package/package.json CHANGED
@@ -1,40 +1,81 @@
1
1
  {
2
2
  "name": "jest-preset-angular",
3
- "version": "8.2.1",
3
+ "version": "8.4.0",
4
4
  "description": "Jest preset configuration for Angular projects",
5
5
  "main": "index.js",
6
6
  "repository": "git@github.com:thymikee/jest-preset-angular.git",
7
7
  "homepage": "https://github.com/thymikee/jest-preset-angular",
8
8
  "author": "Michał Pierzchała <thymikee@gmail.com>",
9
9
  "license": "MIT",
10
- "dependencies": {
11
- "pretty-format": "^26.0.0",
12
- "ts-jest": "^26.0.0"
10
+ "keywords": [
11
+ "jest",
12
+ "typescript",
13
+ "angular",
14
+ "testing"
15
+ ],
16
+ "scripts": {
17
+ "prebuild": "rimraf ./build",
18
+ "build": "tsc -p tsconfig.build.json",
19
+ "prepare": "yarn build",
20
+ "lint": "eslint --ext .js,.ts .",
21
+ "lint:fix": "eslint --fix --ext .js,.ts .",
22
+ "test:ci": "jest -i",
23
+ "test:e2e": "node scripts/e2e.js",
24
+ "changelog": "conventional-changelog -p angular -i ./CHANGELOG.md -s -r 1"
13
25
  },
14
- "devDependencies": {
15
- "@types/jest": "^26.0.0",
16
- "@types/node": "^14.0.4",
17
- "jest": "^26.0.1",
18
- "typescript": "~3.8.3"
26
+ "dependencies": {
27
+ "pretty-format": "26.x",
28
+ "ts-jest": "26.x"
19
29
  },
20
30
  "peerDependencies": {
21
31
  "@angular/core": ">=2.0.0",
22
32
  "@angular/platform-browser-dynamic": ">=2.0.0",
23
33
  "jest": "^26.0.0"
24
34
  },
25
- "jest": {
26
- "preset": "ts-jest",
27
- "globals": {
28
- "ts-jest": {
29
- "tsConfig": "<rootDir>/tsconfig.spec.json"
30
- }
31
- },
32
- "rootDir": "src/__tests__"
35
+ "devDependencies": {
36
+ "@angular-eslint/eslint-plugin": "latest",
37
+ "@angular/core": "^9.1.13",
38
+ "@commitlint/cli": "latest",
39
+ "@commitlint/config-angular": "latest",
40
+ "@types/jest": "26.x",
41
+ "@types/node": "12.x",
42
+ "@typescript-eslint/eslint-plugin": "latest",
43
+ "@typescript-eslint/parser": "latest",
44
+ "conventional-changelog-cli": "2.x",
45
+ "eslint": "7.x",
46
+ "eslint-config-prettier": "latest",
47
+ "eslint-plugin-import": "^2.22.1",
48
+ "eslint-plugin-jest": "latest",
49
+ "eslint-plugin-jsdoc": "latest",
50
+ "eslint-plugin-prefer-arrow": "^1.2.3",
51
+ "eslint-plugin-prettier": "latest",
52
+ "execa": "4.x",
53
+ "fs-extra": "^9.1.0",
54
+ "husky": "4.x",
55
+ "jest": "26.x",
56
+ "lint-staged": "latest",
57
+ "lodash.memoize": "4.x",
58
+ "prettier": "2.x",
59
+ "rxjs": "^6.6.6",
60
+ "ts-jest": "26.x",
61
+ "tslib": "1.14.1",
62
+ "typescript": "3.x",
63
+ "zone.js": "0.10.3"
33
64
  },
34
- "scripts": {
35
- "build": "tsc",
36
- "prepare": "yarn build",
37
- "test": "jest",
38
- "test:ci": "jest -i"
65
+ "husky": {
66
+ "hooks": {
67
+ "pre-commit": "lint-staged",
68
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
69
+ "post-commit": "git reset"
70
+ }
71
+ },
72
+ "lint-staged": {
73
+ "*.{ts,js}": [
74
+ "eslint --fix",
75
+ "git add"
76
+ ]
77
+ },
78
+ "engines": {
79
+ "node": ">= 10"
39
80
  }
40
81
  }
package/setup-jest.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./build/setup-jest');
@@ -1,75 +0,0 @@
1
- version: 2.1
2
- executors:
3
- node-10:
4
- docker:
5
- - image: circleci/node:10
6
-
7
- jobs:
8
- install-dependencies:
9
- executor: node-10
10
- steps:
11
- - checkout
12
- - run: 'sudo yarn global add greenkeeper-lockfile@2'
13
- - run: 'greenkeeper-lockfile-update'
14
- - restore_cache:
15
- keys:
16
- # if lock file changes, we still use increasingly general patterns to restore cache
17
- - yarn-cache-lib-{{ .Branch }}-{{ checksum "yarn.lock" }}
18
- - yarn-cache-lib-{{ .Branch }}-
19
- - run:
20
- name: Install dependencies
21
- command: |
22
- yarn --version
23
- yarn install --frozen-lockfile
24
- - save_cache:
25
- key: yarn-cache-lib-{{ .Branch }}-{{ checksum "yarn.lock" }}
26
- paths:
27
- - ~/.yarn
28
- - ~/.cache/yarn
29
- - ./node_modules
30
- - persist_to_workspace:
31
- root: .
32
- paths: .
33
-
34
- test-library:
35
- executor: node-10
36
- steps:
37
- - attach_workspace:
38
- at: .
39
- - run:
40
- name: Test Library
41
- command: yarn test:ci
42
-
43
- install-test-example:
44
- executor: node-10
45
- steps:
46
- - attach_workspace:
47
- at: .
48
- # skipping cache here as it created issues with the preset in the root
49
- # not being used, as older version in cache was available
50
- - run: 'sudo yarn global add greenkeeper-lockfile@2'
51
- - run: 'greenkeeper-lockfile-update'
52
- - run:
53
- name: Install Example Dependencies
54
- command: |
55
- cd example
56
- yarn install --frozen-lockfile
57
- - run:
58
- name: Test Example
59
- command: |
60
- cd example
61
- yarn test:ci
62
- yarn test:coverage
63
-
64
- workflows:
65
- version: 2
66
- install-and-test:
67
- jobs:
68
- - install-dependencies
69
- - test-library:
70
- requires:
71
- - install-dependencies
72
- - install-test-example:
73
- requires:
74
- - install-dependencies
75
-
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
- <excludeFolder url="file://$MODULE_DIR$/temp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptSettings">
4
- <option name="languageLevel" value="ES6" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/jest-preset-angular.iml" filepath="$PROJECT_DIR$/.idea/jest-preset-angular.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>