apify-test-tools 0.5.7-beta.4 → 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.
- package/.github/workflows/_check_code.yaml +17 -18
- package/.husky/pre-commit +13 -0
- package/CHANGELOG.md +2 -0
- package/CONTRIBUTING.md +5 -0
- package/README.md +39 -43
- package/bin/build.ts +138 -87
- package/bin/diff-changes.ts +52 -23
- package/bin/diff-json-schema.ts +10 -3
- package/bin/git.ts +6 -8
- package/bin/github.ts +7 -6
- package/bin/main.ts +14 -8
- package/bin/slack.ts +6 -2
- package/bin/test-report.ts +55 -44
- package/bin/types.ts +56 -59
- package/bin/utils.ts +17 -12
- package/dist/bin/build.d.ts +1 -1
- package/dist/bin/build.d.ts.map +1 -1
- package/dist/bin/build.js +49 -31
- package/dist/bin/build.js.map +1 -1
- package/dist/bin/diff-changes.d.ts +1 -1
- package/dist/bin/diff-changes.d.ts.map +1 -1
- package/dist/bin/diff-changes.js +15 -3
- package/dist/bin/diff-changes.js.map +1 -1
- package/dist/bin/diff-json-schema.d.ts.map +1 -1
- package/dist/bin/diff-json-schema.js +6 -1
- package/dist/bin/diff-json-schema.js.map +1 -1
- package/dist/bin/git.d.ts +0 -1
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +0 -5
- package/dist/bin/git.js.map +1 -1
- package/dist/bin/github.d.ts +1 -3
- package/dist/bin/github.d.ts.map +1 -1
- package/dist/bin/github.js +5 -5
- package/dist/bin/github.js.map +1 -1
- package/dist/bin/main.js +7 -1
- package/dist/bin/main.js.map +1 -1
- package/dist/bin/slack.d.ts +1 -1
- package/dist/bin/slack.d.ts.map +1 -1
- package/dist/bin/slack.js +1 -1
- package/dist/bin/slack.js.map +1 -1
- package/dist/bin/test-report.d.ts.map +1 -1
- package/dist/bin/test-report.js +9 -3
- package/dist/bin/test-report.js.map +1 -1
- package/dist/bin/types.d.ts +0 -1
- package/dist/bin/types.d.ts.map +1 -1
- package/dist/bin/utils.d.ts.map +1 -1
- package/dist/bin/utils.js +11 -7
- package/dist/bin/utils.js.map +1 -1
- package/dist/lib/extend-expect.d.ts.map +1 -1
- package/dist/lib/extend-expect.js +13 -11
- package/dist/lib/extend-expect.js.map +1 -1
- package/dist/lib/lib.d.ts +3 -2
- package/dist/lib/lib.d.ts.map +1 -1
- package/dist/lib/lib.js +7 -3
- package/dist/lib/lib.js.map +1 -1
- package/dist/lib/run-test-result.d.ts +1 -1
- package/dist/lib/run-test-result.d.ts.map +1 -1
- package/dist/lib/run-test-result.js.map +1 -1
- package/dist/lib/types.d.ts +2 -3
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +4 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/test/unit/bin/diff-changes.test.js +14 -7
- package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
- package/dist/test/unit/bin/diff.test.js +14 -4
- package/dist/test/unit/bin/diff.test.js.map +1 -1
- package/dist/test/unit/bin/git.test.js.map +1 -1
- package/dist/test/unit/custom-matchers.test.js +3 -8
- package/dist/test/unit/custom-matchers.test.js.map +1 -1
- package/dist/test/unit/should-built-and-test.test.js +75 -18
- package/dist/test/unit/should-built-and-test.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.mjs +4 -2
- package/knip.json +1 -1
- package/lib/extend-expect.ts +23 -21
- package/lib/lib.ts +17 -17
- package/lib/run-test-result.ts +6 -2
- package/lib/types.ts +5 -8
- package/lib/utils.ts +13 -9
- package/package.json +10 -3
- package/test/tsconfig.json +2 -4
- package/test/unit/bin/diff-changes.test.ts +14 -7
- package/test/unit/bin/diff.test.ts +19 -21
- package/test/unit/bin/git.test.ts +3 -1
- package/test/unit/custom-matchers.test.ts +10 -9
- package/test/unit/should-built-and-test.test.ts +77 -20
- package/bin/consts.ts +0 -6
- package/dist/bin/consts.d.ts +0 -4
- package/dist/bin/consts.d.ts.map +0 -1
- package/dist/bin/consts.js +0 -6
- package/dist/bin/consts.js.map +0 -1
- package/example-github-events/pull-request.json +0 -523
- 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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
<!-- git-cliff-unreleased-end -->
|
|
19
|
+
|
|
19
20
|
# Changelog
|
|
20
21
|
|
|
21
22
|
## 0.5.5
|
|
@@ -61,6 +62,7 @@ feat: feat: add maxRetriesPerRequest test
|
|
|
61
62
|
## 0.2.3
|
|
62
63
|
|
|
63
64
|
### Lib
|
|
65
|
+
|
|
64
66
|
- feat: add `runId` option to test tests
|
|
65
67
|
- fix: PPE pass won't override overall pass
|
|
66
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: [
|
|
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: [
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
211
|
-
|
|
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
|
-
|
|
220
|
-
|
|
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
|
---
|