apify-test-tools 0.9.1-beta.10 → 0.9.1-beta.11
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/CHANGELOG.md +1 -0
- package/README.md +78 -27
- package/bin/utils/config/parser.ts +6 -5
- package/bin/utils/config/structures/base.ts +5 -1
- package/bin/utils/config/structures/grouped.ts +40 -0
- package/bin/utils/config/structures/legacy.ts +3 -1
- package/dist/bin/utils/config/parser.d.ts.map +1 -1
- package/dist/bin/utils/config/parser.js +6 -5
- package/dist/bin/utils/config/parser.js.map +1 -1
- package/dist/bin/utils/config/structures/base.d.ts +3 -2
- package/dist/bin/utils/config/structures/base.d.ts.map +1 -1
- package/dist/bin/utils/config/structures/base.js +1 -0
- package/dist/bin/utils/config/structures/base.js.map +1 -1
- package/dist/bin/utils/config/structures/grouped.d.ts +6 -0
- package/dist/bin/utils/config/structures/grouped.d.ts.map +1 -0
- package/dist/bin/utils/config/structures/grouped.js +29 -0
- package/dist/bin/utils/config/structures/grouped.js.map +1 -0
- package/dist/bin/utils/config/structures/legacy.d.ts +1 -1
- package/dist/bin/utils/config/structures/legacy.d.ts.map +1 -1
- package/dist/bin/utils/config/structures/legacy.js +1 -1
- package/dist/bin/utils/config/structures/legacy.js.map +1 -1
- package/dist/test/unit/bin/utils/config/load-config.test.js +1 -0
- package/dist/test/unit/bin/utils/config/load-config.test.js.map +1 -1
- package/dist/test/unit/bin/utils/config/parser.test.js +23 -5
- package/dist/test/unit/bin/utils/config/parser.test.js.map +1 -1
- package/dist/test/unit/bin/utils/config/structures/grouped.test.d.ts +2 -0
- package/dist/test/unit/bin/utils/config/structures/grouped.test.d.ts.map +1 -0
- package/dist/test/unit/bin/utils/config/structures/grouped.test.js +75 -0
- package/dist/test/unit/bin/utils/config/structures/grouped.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/test/unit/bin/utils/config/load-config.test.ts +1 -0
- package/test/unit/bin/utils/config/parser.test.ts +26 -5
- package/test/unit/bin/utils/config/structures/grouped.test.ts +90 -0
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
import { _privates, parseConfigFile } from '../../../../../bin/utils/config/parser.js';
|
|
4
4
|
import { CONFIG_FILE_STRATEGY } from '../../../../../bin/utils/config/structures/base.js';
|
|
5
|
+
import { GROUPED_PARSER } from '../../../../../bin/utils/config/structures/grouped.js';
|
|
5
6
|
import { LEGACY_PARSER } from '../../../../../bin/utils/config/structures/legacy.js';
|
|
6
7
|
|
|
7
8
|
const { selectStrategy, verifyConfiguration } = _privates;
|
|
@@ -10,27 +11,31 @@ const actor = (fields: Record<string, unknown> = {}) => ({
|
|
|
10
11
|
folder: 'actors/shopify',
|
|
11
12
|
actorFullName: 'myteam/shopify',
|
|
12
13
|
tokenEnvVar: 'APIFY_TOKEN',
|
|
14
|
+
overrideActorContext: undefined,
|
|
13
15
|
...fields,
|
|
14
16
|
});
|
|
15
17
|
|
|
16
18
|
describe('selectStrategy', () => {
|
|
17
19
|
it('falls back to the legacy strategy when no mode is declared', () => {
|
|
18
|
-
expect(selectStrategy(
|
|
20
|
+
expect(selectStrategy({})).toBe(LEGACY_PARSER);
|
|
19
21
|
});
|
|
20
22
|
|
|
21
|
-
it(
|
|
22
|
-
|
|
23
|
+
it.each([
|
|
24
|
+
[CONFIG_FILE_STRATEGY.LEGACY, LEGACY_PARSER],
|
|
25
|
+
[CONFIG_FILE_STRATEGY.GROUPED, GROUPED_PARSER],
|
|
26
|
+
])('honours an explicit "%s" mode', (mode, expected) => {
|
|
27
|
+
expect(selectStrategy({ mode })).toBe(expected);
|
|
23
28
|
});
|
|
24
29
|
|
|
25
30
|
it('throws on a mode no strategy is registered for', () => {
|
|
26
|
-
expect(() => selectStrategy('some-nonexistent-mode')).toThrow(
|
|
31
|
+
expect(() => selectStrategy('some-nonexistent-mode')).toThrow();
|
|
27
32
|
});
|
|
28
33
|
});
|
|
29
34
|
|
|
30
35
|
describe('verifyConfiguration', () => {
|
|
31
36
|
it('resolves the repo root to "" and gets rid of trailing slashes', () => {
|
|
32
37
|
const result = verifyConfiguration([
|
|
33
|
-
{ folder: '.', actorFullName: 'myteam/root', tokenEnvVar: 'APIFY_TOKEN' },
|
|
38
|
+
{ folder: '.', actorFullName: 'myteam/root', tokenEnvVar: 'APIFY_TOKEN', overrideActorContext: undefined },
|
|
34
39
|
{
|
|
35
40
|
folder: 'actors/shopify/',
|
|
36
41
|
actorFullName: 'myteam/shopify',
|
|
@@ -124,6 +129,22 @@ describe('parseConfigFile', () => {
|
|
|
124
129
|
]);
|
|
125
130
|
});
|
|
126
131
|
|
|
132
|
+
it('parses a grouped config file, which needs mode to be stripped', () => {
|
|
133
|
+
expect(
|
|
134
|
+
parseConfigFile({
|
|
135
|
+
mode: CONFIG_FILE_STRATEGY.GROUPED,
|
|
136
|
+
groups: {
|
|
137
|
+
myteam: {
|
|
138
|
+
actors: [{ folder: 'actors/shopify/', actorFullName: 'myteam/shopify' }],
|
|
139
|
+
tokenEnvVar: 'APIFY_TOKEN',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
).toEqual([
|
|
144
|
+
actor({ folder: 'actors/shopify', actorFullName: 'myteam/shopify', overrideActorContext: undefined }),
|
|
145
|
+
]);
|
|
146
|
+
});
|
|
147
|
+
|
|
127
148
|
it('surfaces cross-entry violations from verifyConfiguration', () => {
|
|
128
149
|
expect(() =>
|
|
129
150
|
parseConfigFile({
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { GROUPED_PARSER } from '../../../../../../bin/utils/config/structures/grouped.js';
|
|
4
|
+
|
|
5
|
+
const actor = (fields: Record<string, unknown> = {}) => ({
|
|
6
|
+
folder: 'actors/shopify',
|
|
7
|
+
actorFullName: 'myteam/shopify',
|
|
8
|
+
...fields,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const group = (fields: Record<string, unknown> = {}) => ({
|
|
12
|
+
actors: [actor()],
|
|
13
|
+
tokenEnvVar: 'APIFY_TOKEN',
|
|
14
|
+
...fields,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('GROUPED_PARSER', () => {
|
|
18
|
+
it('flattens every group into one list, handing each actor its group’s settings', () => {
|
|
19
|
+
expect(
|
|
20
|
+
GROUPED_PARSER.parse({
|
|
21
|
+
groups: {
|
|
22
|
+
myteam: {
|
|
23
|
+
actors: [actor(), actor({ folder: 'actors/email', actorFullName: 'myteam/email' })],
|
|
24
|
+
tokenEnvVar: 'APIFY_TOKEN_MYTEAM',
|
|
25
|
+
overrideActorContext: ['packages'],
|
|
26
|
+
},
|
|
27
|
+
other: { actors: [actor({ folder: 'actors/x', actorFullName: 'other/x' })], tokenEnvVar: 'TOKEN' },
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
).toEqual([
|
|
31
|
+
{
|
|
32
|
+
folder: 'actors/shopify',
|
|
33
|
+
actorFullName: 'myteam/shopify',
|
|
34
|
+
tokenEnvVar: 'APIFY_TOKEN_MYTEAM',
|
|
35
|
+
overrideActorContext: ['packages'],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
folder: 'actors/email',
|
|
39
|
+
actorFullName: 'myteam/email',
|
|
40
|
+
tokenEnvVar: 'APIFY_TOKEN_MYTEAM',
|
|
41
|
+
overrideActorContext: ['packages'],
|
|
42
|
+
},
|
|
43
|
+
{ folder: 'actors/x', actorFullName: 'other/x', tokenEnvVar: 'TOKEN', overrideActorContext: undefined },
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('ignores the group key entirely', () => {
|
|
48
|
+
expect(GROUPED_PARSER.parse({ groups: { 'not-a-folder-at-all': group() } })).toEqual([
|
|
49
|
+
{ folder: 'actors/shopify', actorFullName: 'myteam/shopify', tokenEnvVar: 'APIFY_TOKEN' },
|
|
50
|
+
]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('allows actors to override some fields', () => {
|
|
54
|
+
expect(
|
|
55
|
+
GROUPED_PARSER.parse({ groups: { myteam: group({ actors: [actor({ tokenEnvVar: 'FROM_ACTOR' })] }) } }),
|
|
56
|
+
).toEqual([{ folder: 'actors/shopify', actorFullName: 'myteam/shopify', tokenEnvVar: 'FROM_ACTOR' }]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("returns the entries as written — normalizing is not this layer's job", () => {
|
|
60
|
+
const raw = actor({ folder: 'actors/shopify/' });
|
|
61
|
+
|
|
62
|
+
expect(
|
|
63
|
+
GROUPED_PARSER.parse({ groups: { myteam: group({ actors: [raw], overrideActorContext: ['packages/'] }) } }),
|
|
64
|
+
).toEqual([{ ...raw, tokenEnvVar: 'APIFY_TOKEN', overrideActorContext: ['packages/'] }]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('rejects a config with no groups (and thus no actors)', () => {
|
|
68
|
+
expect(() => GROUPED_PARSER.parse({})).toThrow();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('reports problems from every group at once instead of only the first', () => {
|
|
72
|
+
const message = (() => {
|
|
73
|
+
try {
|
|
74
|
+
GROUPED_PARSER.parse({
|
|
75
|
+
groups: {
|
|
76
|
+
myteam: { actors: [actor({ folder: 123 })], tokenEnvVar: 'APIFY_TOKEN' },
|
|
77
|
+
other: { actors: [actor({ actorFullName: 'nope' })] },
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
throw new Error('Function should have thrown');
|
|
81
|
+
} catch (err) {
|
|
82
|
+
return (err as Error).message;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
|
|
86
|
+
expect(message).toContain('myteam.actors[0].folder');
|
|
87
|
+
expect(message).toContain('other.actors[0].actorFullName');
|
|
88
|
+
expect(message).toContain('other.tokenEnvVar');
|
|
89
|
+
});
|
|
90
|
+
});
|