apify-test-tools 0.5.7-beta.3 → 0.5.7-beta.5

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.
Files changed (95) hide show
  1. package/.github/workflows/_check_code.yaml +17 -18
  2. package/.husky/pre-commit +13 -0
  3. package/CHANGELOG.md +3 -0
  4. package/CONTRIBUTING.md +5 -0
  5. package/README.md +39 -43
  6. package/bin/build.ts +138 -87
  7. package/bin/diff-changes.ts +52 -23
  8. package/bin/diff-json-schema.ts +10 -3
  9. package/bin/git.ts +6 -8
  10. package/bin/github.ts +7 -6
  11. package/bin/main.ts +14 -8
  12. package/bin/slack.ts +6 -2
  13. package/bin/test-report.ts +55 -44
  14. package/bin/types.ts +56 -59
  15. package/bin/utils.ts +17 -12
  16. package/dist/bin/build.d.ts +1 -1
  17. package/dist/bin/build.d.ts.map +1 -1
  18. package/dist/bin/build.js +49 -31
  19. package/dist/bin/build.js.map +1 -1
  20. package/dist/bin/diff-changes.d.ts +1 -1
  21. package/dist/bin/diff-changes.d.ts.map +1 -1
  22. package/dist/bin/diff-changes.js +15 -3
  23. package/dist/bin/diff-changes.js.map +1 -1
  24. package/dist/bin/diff-json-schema.d.ts.map +1 -1
  25. package/dist/bin/diff-json-schema.js +6 -1
  26. package/dist/bin/diff-json-schema.js.map +1 -1
  27. package/dist/bin/git.d.ts +0 -1
  28. package/dist/bin/git.d.ts.map +1 -1
  29. package/dist/bin/git.js +0 -5
  30. package/dist/bin/git.js.map +1 -1
  31. package/dist/bin/github.d.ts +1 -3
  32. package/dist/bin/github.d.ts.map +1 -1
  33. package/dist/bin/github.js +5 -5
  34. package/dist/bin/github.js.map +1 -1
  35. package/dist/bin/main.js +7 -1
  36. package/dist/bin/main.js.map +1 -1
  37. package/dist/bin/slack.d.ts +1 -1
  38. package/dist/bin/slack.d.ts.map +1 -1
  39. package/dist/bin/slack.js +1 -1
  40. package/dist/bin/slack.js.map +1 -1
  41. package/dist/bin/test-report.d.ts.map +1 -1
  42. package/dist/bin/test-report.js +9 -3
  43. package/dist/bin/test-report.js.map +1 -1
  44. package/dist/bin/types.d.ts +0 -1
  45. package/dist/bin/types.d.ts.map +1 -1
  46. package/dist/bin/utils.d.ts.map +1 -1
  47. package/dist/bin/utils.js +11 -7
  48. package/dist/bin/utils.js.map +1 -1
  49. package/dist/lib/extend-expect.d.ts.map +1 -1
  50. package/dist/lib/extend-expect.js +13 -11
  51. package/dist/lib/extend-expect.js.map +1 -1
  52. package/dist/lib/lib.d.ts +3 -2
  53. package/dist/lib/lib.d.ts.map +1 -1
  54. package/dist/lib/lib.js +7 -3
  55. package/dist/lib/lib.js.map +1 -1
  56. package/dist/lib/run-test-result.d.ts +1 -1
  57. package/dist/lib/run-test-result.d.ts.map +1 -1
  58. package/dist/lib/run-test-result.js.map +1 -1
  59. package/dist/lib/types.d.ts +2 -3
  60. package/dist/lib/types.d.ts.map +1 -1
  61. package/dist/lib/utils.d.ts +1 -1
  62. package/dist/lib/utils.d.ts.map +1 -1
  63. package/dist/lib/utils.js +4 -1
  64. package/dist/lib/utils.js.map +1 -1
  65. package/dist/test/unit/bin/diff-changes.test.js +14 -7
  66. package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
  67. package/dist/test/unit/bin/diff.test.js +14 -4
  68. package/dist/test/unit/bin/diff.test.js.map +1 -1
  69. package/dist/test/unit/bin/git.test.js.map +1 -1
  70. package/dist/test/unit/custom-matchers.test.js +3 -8
  71. package/dist/test/unit/custom-matchers.test.js.map +1 -1
  72. package/dist/test/unit/should-built-and-test.test.js +75 -18
  73. package/dist/test/unit/should-built-and-test.test.js.map +1 -1
  74. package/dist/tsconfig.tsbuildinfo +1 -1
  75. package/eslint.config.mjs +4 -2
  76. package/knip.json +1 -1
  77. package/lib/extend-expect.ts +23 -21
  78. package/lib/lib.ts +17 -17
  79. package/lib/run-test-result.ts +6 -2
  80. package/lib/types.ts +5 -8
  81. package/lib/utils.ts +13 -9
  82. package/package.json +10 -3
  83. package/test/tsconfig.json +2 -4
  84. package/test/unit/bin/diff-changes.test.ts +14 -7
  85. package/test/unit/bin/diff.test.ts +19 -21
  86. package/test/unit/bin/git.test.ts +3 -1
  87. package/test/unit/custom-matchers.test.ts +10 -9
  88. package/test/unit/should-built-and-test.test.ts +77 -20
  89. package/bin/consts.ts +0 -6
  90. package/dist/bin/consts.d.ts +0 -4
  91. package/dist/bin/consts.d.ts.map +0 -1
  92. package/dist/bin/consts.js +0 -6
  93. package/dist/bin/consts.js.map +0 -1
  94. package/example-github-events/pull-request.json +0 -523
  95. package/example-github-events/push.json +0 -216
@@ -16,7 +16,7 @@ jobs:
16
16
  - name: Run actionlint
17
17
  uses: rhysd/actionlint@v1.7.11
18
18
 
19
- # TODO: Fix spell check after we merge current PRs
19
+ # TODO: Fix spell check after we merge current PRs
20
20
  # spell_check:
21
21
  # name: Spell check
22
22
  # runs-on: ubuntu-latest
@@ -26,23 +26,22 @@ jobs:
26
26
  # - name: Check spelling with typos
27
27
  # uses: crate-ci/typos@v1
28
28
 
29
- # TODO: Fix lint after we merge current PRs
30
- # lint_check:
31
- # name: Lint check
32
- # runs-on: ubuntu-latest
33
- # steps:
34
- # - name: Checkout repository
35
- # uses: actions/checkout@v6
36
- # - name: Use Node.js
37
- # uses: actions/setup-node@v6
38
- # with:
39
- # node-version: 24
40
- # cache: 'npm'
41
- # cache-dependency-path: 'package-lock.json'
42
- # - name: Install dependencies
43
- # run: npm ci
44
- # - name: Lint
45
- # run: npm run lint
29
+ lint_check:
30
+ name: Lint check
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - name: Checkout repository
34
+ uses: actions/checkout@v6
35
+ - name: Use Node.js
36
+ uses: actions/setup-node@v6
37
+ with:
38
+ node-version: 24
39
+ cache: 'npm'
40
+ cache-dependency-path: 'package-lock.json'
41
+ - name: Install dependencies
42
+ run: npm ci
43
+ - name: Lint
44
+ run: npm run lint
46
45
 
47
46
  type_check:
48
47
  name: Type check
@@ -0,0 +1,13 @@
1
+ echo "pre-commit: typechecking, linting, testing, checking code formatting, checking for unused exports & validating schemas"
2
+
3
+
4
+ npm test
5
+ npm run format:check
6
+ # We typecheck & lint last when we know our code works
7
+ npx tsc --noEmit
8
+ npx lint-staged
9
+
10
+ # Activate once we resolv unused delete old builds
11
+ # npm run check-unused
12
+
13
+ echo "pre-commit: passed"
package/CHANGELOG.md CHANGED
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
8
8
  ### 🚀 Features
9
9
 
10
10
  - Make slack notification explictly opt in ([#60](https://github.com/apify/apify-test-tools/pull/60)) ([32fda72](https://github.com/apify/apify-test-tools/commit/32fda72726896d90c7a1444977b87e4aa8e8d247)) by [@ruocco-l](https://github.com/ruocco-l), closes [#55](https://github.com/apify/apify-test-tools/issues/55)
11
+ - **bin:** Don't test on nonfunctional changes in json files ([#56](https://github.com/apify/apify-test-tools/pull/56)) ([5f3c7c5](https://github.com/apify/apify-test-tools/commit/5f3c7c56c710a9120f894bdb6fd13855bf46f9f8)) by [@metalwarrior665](https://github.com/metalwarrior665), closes [#54](https://github.com/apify/apify-test-tools/issues/54)
11
12
 
12
13
  ### Debug
13
14
 
@@ -15,6 +16,7 @@ All notable changes to this project will be documented in this file.
15
16
 
16
17
 
17
18
  <!-- git-cliff-unreleased-end -->
19
+
18
20
  # Changelog
19
21
 
20
22
  ## 0.5.5
@@ -60,6 +62,7 @@ feat: feat: add maxRetriesPerRequest test
60
62
  ## 0.2.3
61
63
 
62
64
  ### Lib
65
+
63
66
  - feat: add `runId` option to test tests
64
67
  - fix: PPE pass won't override overall pass
65
68
 
package/CONTRIBUTING.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Contributing
2
2
 
3
3
  The package consists of two parts:
4
+
4
5
  - cli located in `bin/`
5
6
  - test library located in `lib`
6
7
 
@@ -22,6 +23,7 @@ The package consists of two parts:
22
23
  ### Development setup
23
24
 
24
25
  1. Clone and build `apify-test-tools` repo:
26
+
25
27
  ```sh
26
28
  git clone git@github.com:apify-projects/apify-test-tools.git
27
29
  cd apify-test-tools
@@ -30,6 +32,7 @@ npm run build
30
32
  ```
31
33
 
32
34
  For testing purposes, we use `testing-repo-for-github-actions` repo so that we don't mess with the production repos:
35
+
33
36
  ```sh
34
37
  git clone git@github.com:apify-store/testing-repo-for-github-actions.git
35
38
  ```
@@ -37,6 +40,7 @@ git clone git@github.com:apify-store/testing-repo-for-github-actions.git
37
40
  #### Working on the CLI
38
41
 
39
42
  To work on the library, you just need to define `GITHUB_WORKSPACE` to tell the cli where you repo is located:
43
+
40
44
  ```sh
41
45
  export GITHUB_WORKSPACE=../path/to/testing-repo-for-github-actions # path to the repo
42
46
  npx tsx bin/main.ts --help
@@ -46,6 +50,7 @@ npx tsx bin/main.ts get-commits --target-branch master --source-branch feat/test
46
50
  #### Working on the library
47
51
 
48
52
  You need to istall the local version of `apify-test-tools` in your cloned `testing-repo-for-github-actions`:
53
+
49
54
  ```sh
50
55
  npm i -D ../path/to/apify-test-tools
51
56
  ```
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ## Getting Started
6
6
 
7
7
  1. Install the package `npm i -D apify-test-tools`
8
- - because it uses [annotate](https://vitest.dev/guide/test-context.html#annotate), `vitest` version to be at least `3.2.0`
8
+ - because it uses [annotate](https://vitest.dev/guide/test-context.html#annotate), `vitest` version to be at least `3.2.0`
9
9
  - make sure that `target` and `module` in your `tsconfig.json`'s `compilerOptions` are set to `ES2022`
10
10
  2. create test directories: `mkdir -p test/platform/core`
11
11
  - core (hourly) tests should go to `test/platform/core`
@@ -13,6 +13,7 @@
13
13
  3. setup github worklows TODO
14
14
 
15
15
  File structure:
16
+
16
17
  ```
17
18
  google-maps
18
19
  ├── actors
@@ -20,7 +21,7 @@ google-maps
20
21
  └── test
21
22
  ├── unit
22
23
  └── platform
23
- ├── core <- Core tests need to be inside core directory
24
+ ├── core <- Core tests need to be inside core directory
24
25
  │ └── core.test.ts
25
26
  ├── some.test.ts <- Other tests can be defined anywhere inside platform directory
26
27
  └── some-other.test.ts
@@ -73,7 +74,7 @@ name: PR Test
73
74
 
74
75
  on:
75
76
  pull_request:
76
- branches: [ master ]
77
+ branches: [master]
77
78
 
78
79
  jobs:
79
80
  buildDevelAndTest:
@@ -88,7 +89,7 @@ name: Release latest
88
89
 
89
90
  on:
90
91
  push:
91
- branches: [ master ]
92
+ branches: [master]
92
93
 
93
94
  jobs:
94
95
  buildLatest:
@@ -102,9 +103,10 @@ jobs:
102
103
 
103
104
  ### Test structure
104
105
 
105
- To run the tests concurrently, we had to start the run outside of `it` and then call `await` inside. This is now no longer needed and everything can be inside `it` aka `testActor`.
106
+ To run the tests concurrently, we had to start the run outside of `it` and then call `await` inside. This is now no longer needed and everything can be inside `it` aka `testActor`.
106
107
 
107
108
  Before:
109
+
108
110
  ```ts
109
111
  ({ it, xit, run, expect, expectAsync, input, describe }: TestSpecInputs) => {
110
112
  describe('test', () => {
@@ -112,7 +114,7 @@ Before:
112
114
  const runPromise = run({ actorId, input })
113
115
  it('actor test 1', async () => {
114
116
  const runResult = await runPromise;
115
-
117
+
116
118
  // your checks
117
119
  });
118
120
  }
@@ -121,25 +123,26 @@ Before:
121
123
  const runPromise = run({ actorId, input })
122
124
  it('actor test 2', async () => {
123
125
  const runResult = await runPromise;
124
-
126
+
125
127
  // your checks
126
128
  });
127
- }
129
+ }
128
130
  });
129
131
  })
130
132
  ```
131
133
 
132
134
  After:
135
+
133
136
  ```ts
134
137
  import { describe, testActor } from 'apify-test-tools';
135
138
 
136
139
  describe('test', () => {
137
140
  testActor(actorId, 'actor test 1', async ({ expect, run }) => {
138
141
  const runResult = await run({ input })
139
-
142
+
140
143
  // your checks
141
144
  )};
142
-
145
+
143
146
  testActor(actorId, 'actor test 2', async ({ expect, run }) => {
144
147
  const runResult = await run({ input })
145
148
 
@@ -155,6 +158,7 @@ describe('test', () => {
155
158
  ### Validating basic run attributes
156
159
 
157
160
  Before:
161
+
158
162
  ```ts
159
163
  await expectAsync(runResult).toHaveStatus('SUCCEEDED');
160
164
 
@@ -164,41 +168,36 @@ await expectAsync(runResult).withLog((log) => {
164
168
  });
165
169
 
166
170
  await expectAsync(runResult).withStatistics((stats) => {
167
- expect(stats.requestsRetries)
168
- .withContext(runResult.format('Request retries'))
169
- .toBeLessThan(3);
170
- expect(stats.crawlerRuntimeMillis)
171
- .withContext(runResult.format('Run time'))
172
- .toBeWithinRange(600, 600_000)
173
- })
174
-
171
+ expect(stats.requestsRetries).withContext(runResult.format('Request retries')).toBeLessThan(3);
172
+ expect(stats.crawlerRuntimeMillis).withContext(runResult.format('Run time')).toBeWithinRange(600, 600_000);
173
+ });
174
+
175
175
  await expectAsync(runResult).withDataset(({ dataset }) => {
176
- expect(dataset.items?.length)
177
- .withContext(runResult.format('Dataset cleanItemCount'))
178
- .toBe(100);
179
- })
176
+ expect(dataset.items?.length).withContext(runResult.format('Dataset cleanItemCount')).toBe(100);
177
+ });
180
178
  ```
181
179
 
182
180
  After:
181
+
183
182
  ```ts
184
183
  await expect(runResult).toFinishWith({
185
- datasetItemCount: 100,
186
- })
184
+ datasetItemCount: 100,
185
+ });
187
186
  ```
188
187
 
189
188
  You can also specify a range:
190
189
 
191
190
  ```ts
192
191
  await expect(runResult).toFinishWith({
193
- datasetItemCount: { min: 80, max: 120 },
194
- })
192
+ datasetItemCount: { min: 80, max: 120 },
193
+ });
195
194
  ```
196
195
 
197
196
  Here is full example of what you can validate with `toFinishWith`
198
197
 
199
198
  ```ts
200
199
  await expect(runResult).toFinishWith({
201
- // These are default
200
+ // These are default
202
201
  status: 'SUCCEEDED',
203
202
  duration: {
204
203
  min: 600, // 0.6 sec
@@ -206,20 +205,17 @@ await expect(runResult).toFinishWith({
206
205
  },
207
206
  failedRequests: 0,
208
207
  requestsRetries: { max: 3 },
209
- forbiddenLogs: [
210
- 'ReferenceError',
211
- 'TypeError',
212
- ],
213
-
214
- // only datasetItemCount is required
215
- datasetItemCount: { min: 80, max: 120 },
216
-
208
+ forbiddenLogs: ['ReferenceError', 'TypeError'],
209
+
210
+ // only datasetItemCount is required
211
+ datasetItemCount: { min: 80, max: 120 },
212
+
217
213
  // optional
218
214
  chargedEventCounts: {
219
- 'actor-start': 1,
220
- 'place-scraped': 9,
221
- },
222
- })
215
+ 'actor-start': 1,
216
+ 'place-scraped': 9,
217
+ },
218
+ });
223
219
  ```
224
220
 
225
221
  ---
@@ -227,15 +223,15 @@ await expect(runResult).toFinishWith({
227
223
  ### Custom validations
228
224
 
229
225
  Before:
226
+
230
227
  ```ts
231
- expect(place.title)
232
- .withContext(runResult.format(`London Eye's title`))
233
- .toEqual('lastminute.com London Eye')
228
+ expect(place.title).withContext(runResult.format(`London Eye's title`)).toEqual('lastminute.com London Eye');
234
229
  ```
235
230
 
236
231
  After:
232
+
237
233
  ```ts
238
- expect(place.title, `London Eye's title`).toEqual('lastminute.com London Eye')
234
+ expect(place.title, `London Eye's title`).toEqual('lastminute.com London Eye');
239
235
  ```
240
236
 
241
237
  ---