apify-test-tools 0.9.1-beta.4 → 0.9.1-beta.6
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/on_pull_request.yaml +1 -1
- package/.prettierignore +3 -0
- package/.vscode/settings.json +2 -1
- package/CHANGELOG.md +4 -0
- package/bin/main.ts +2 -1
- package/bin/types.ts +0 -11
- package/bin/utils/config/load-config.ts +133 -0
- package/bin/utils/config/parser.ts +88 -0
- package/bin/utils/config/structures/base.ts +61 -0
- package/bin/utils/config/structures/legacy.ts +20 -0
- package/bin/utils/json-file.ts +55 -0
- package/bin/utils.ts +0 -138
- package/dist/bin/main.d.ts.map +1 -1
- package/dist/bin/main.js +2 -1
- package/dist/bin/main.js.map +1 -1
- package/dist/bin/types.d.ts +0 -9
- package/dist/bin/types.d.ts.map +1 -1
- package/dist/bin/utils/config/load-config.d.ts +13 -0
- package/dist/bin/utils/config/load-config.d.ts.map +1 -0
- package/dist/bin/utils/config/load-config.js +99 -0
- package/dist/bin/utils/config/load-config.js.map +1 -0
- package/dist/bin/utils/config/parser.d.ts +19 -0
- package/dist/bin/utils/config/parser.d.ts.map +1 -0
- package/dist/bin/utils/config/parser.js +72 -0
- package/dist/bin/utils/config/parser.js.map +1 -0
- package/dist/bin/utils/config/structures/base.d.ts +35 -0
- package/dist/bin/utils/config/structures/base.d.ts.map +1 -0
- package/dist/bin/utils/config/structures/base.js +40 -0
- package/dist/bin/utils/config/structures/base.js.map +1 -0
- package/dist/bin/utils/config/structures/legacy.d.ts +6 -0
- package/dist/bin/utils/config/structures/legacy.d.ts.map +1 -0
- package/dist/bin/utils/config/structures/legacy.js +14 -0
- package/dist/bin/utils/config/structures/legacy.js.map +1 -0
- package/dist/bin/utils/json-file.d.ts +20 -0
- package/dist/bin/utils/json-file.d.ts.map +1 -0
- package/dist/bin/utils/json-file.js +42 -0
- package/dist/bin/utils/json-file.js.map +1 -0
- package/dist/bin/utils.d.ts +0 -6
- package/dist/bin/utils.d.ts.map +1 -1
- package/dist/bin/utils.js +0 -98
- package/dist/bin/utils.js.map +1 -1
- package/dist/test/unit/bin/utils/config/load-config.test.d.ts +2 -0
- package/dist/test/unit/bin/utils/config/load-config.test.d.ts.map +1 -0
- package/dist/test/unit/bin/utils/config/load-config.test.js +138 -0
- package/dist/test/unit/bin/utils/config/load-config.test.js.map +1 -0
- package/dist/test/unit/bin/utils/config/parser.test.d.ts +2 -0
- package/dist/test/unit/bin/utils/config/parser.test.d.ts.map +1 -0
- package/dist/test/unit/bin/utils/config/parser.test.js +111 -0
- package/dist/test/unit/bin/utils/config/parser.test.js.map +1 -0
- package/dist/test/unit/bin/utils/config/structures/base.test.d.ts +2 -0
- package/dist/test/unit/bin/utils/config/structures/base.test.d.ts.map +1 -0
- package/dist/test/unit/bin/utils/config/structures/base.test.js +74 -0
- package/dist/test/unit/bin/utils/config/structures/base.test.js.map +1 -0
- package/dist/test/unit/bin/utils/config/structures/legacy.test.d.ts +2 -0
- package/dist/test/unit/bin/utils/config/structures/legacy.test.d.ts.map +1 -0
- package/dist/test/unit/bin/utils/config/structures/legacy.test.js +63 -0
- package/dist/test/unit/bin/utils/config/structures/legacy.test.js.map +1 -0
- package/dist/test/unit/bin/utils/files.test.d.ts +2 -0
- package/dist/test/unit/bin/utils/files.test.d.ts.map +1 -0
- package/dist/test/unit/bin/utils/files.test.js +117 -0
- package/dist/test/unit/bin/utils/files.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/test/fixtures/bin/utils/files/array.json +1 -0
- package/test/fixtures/bin/utils/files/comments.jsonc +4 -0
- package/test/fixtures/bin/utils/files/directory.json/.gitkeep +0 -0
- package/test/fixtures/bin/utils/files/empty-object.json +1 -0
- package/test/fixtures/bin/utils/files/empty.json +0 -0
- package/test/fixtures/bin/utils/files/malformed.json +1 -0
- package/test/fixtures/bin/utils/files/nested.json +6 -0
- package/test/fixtures/bin/utils/files/no-json-extension.actorrc +1 -0
- package/test/fixtures/bin/utils/files/null.json +1 -0
- package/test/fixtures/bin/utils/files/number.json +1 -0
- package/test/fixtures/bin/utils/files/unreadable.json +1 -0
- package/test/tsconfig.json +4 -2
- package/test/unit/bin/utils/config/load-config.test.ts +179 -0
- package/test/unit/bin/utils/config/parser.test.ts +137 -0
- package/test/unit/bin/utils/config/structures/base.test.ts +83 -0
- package/test/unit/bin/utils/config/structures/legacy.test.ts +78 -0
- package/test/unit/bin/utils/files.test.ts +158 -0
- package/dist/test/unit/bin/utils.test.d.ts +0 -2
- package/dist/test/unit/bin/utils.test.d.ts.map +0 -1
- package/dist/test/unit/bin/utils.test.js +0 -321
- package/dist/test/unit/bin/utils.test.js.map +0 -1
- package/test/unit/bin/utils.test.ts +0 -381
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { CONFIG_FILE_NAME, readConfigFile } from '../../../bin/utils.js';
|
|
4
|
-
|
|
5
|
-
const { fsMock } = vi.hoisted(() => ({
|
|
6
|
-
fsMock: {
|
|
7
|
-
readFile: vi.fn(),
|
|
8
|
-
},
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
vi.mock('node:fs/promises', () => ({ default: fsMock }));
|
|
12
|
-
|
|
13
|
-
afterEach(() => vi.restoreAllMocks());
|
|
14
|
-
|
|
15
|
-
const emptyActorSelection = { actors: [], ignore: [] };
|
|
16
|
-
|
|
17
|
-
const validConfig = (actors: object[]) => JSON.stringify({ actors });
|
|
18
|
-
const actorJson = (fields: Record<string, unknown> = {}) => JSON.stringify(fields);
|
|
19
|
-
|
|
20
|
-
const expectFileRead = (filePath: string) => {
|
|
21
|
-
expect(fsMock.readFile).toHaveBeenCalledWith(filePath, expect.anything());
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const mockFiles = (files: Record<string, string>) => {
|
|
25
|
-
fsMock.readFile.mockImplementation(async (filePath: string) => {
|
|
26
|
-
if (filePath in files) return Promise.resolve(files[filePath]);
|
|
27
|
-
return Promise.reject(new Error(`ENOENT: ${filePath}`));
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
describe('readConfigFile', () => {
|
|
32
|
-
it('returns correct ActorConfig[] for a valid config', async () => {
|
|
33
|
-
mockFiles({
|
|
34
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
35
|
-
{
|
|
36
|
-
folder: 'actors/shopify',
|
|
37
|
-
actorFullName: 'myteam/shopify-scraper',
|
|
38
|
-
tokenEnvVar: 'APIFY_TOKEN_MYTEAM',
|
|
39
|
-
},
|
|
40
|
-
]),
|
|
41
|
-
'actors/shopify/.actor/actor.json': actorJson({ dockerContextDir: '../../..' }),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
45
|
-
expectFileRead('actors/shopify/.actor/actor.json');
|
|
46
|
-
expect(result).toEqual([
|
|
47
|
-
{
|
|
48
|
-
actorFullName: 'myteam/shopify-scraper',
|
|
49
|
-
folder: 'actors/shopify',
|
|
50
|
-
tokenEnvVar: 'APIFY_TOKEN_MYTEAM',
|
|
51
|
-
dockerContextDir: '',
|
|
52
|
-
contextPaths: [''],
|
|
53
|
-
},
|
|
54
|
-
]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('normalizes folder "." to ""', async () => {
|
|
58
|
-
mockFiles({
|
|
59
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
60
|
-
{ folder: '.', actorFullName: 'apify/my-actor', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
61
|
-
]),
|
|
62
|
-
'.actor/actor.json': actorJson({}),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
66
|
-
expect(result[0].folder).toBe('');
|
|
67
|
-
expectFileRead('.actor/actor.json');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('defaults dockerContextDir to actor folder when absent from actor.json', async () => {
|
|
71
|
-
mockFiles({
|
|
72
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
73
|
-
{ folder: 'actors/web-scraper', actorFullName: 'apify/web-scraper', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
74
|
-
]),
|
|
75
|
-
'actors/web-scraper/.actor/actor.json': actorJson({}),
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
79
|
-
expect(result[0].dockerContextDir).toBe('actors/web-scraper');
|
|
80
|
-
expect(result[0].contextPaths).toEqual(['actors/web-scraper']);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('resolves dockerContextDir relative to .actor/ folder', async () => {
|
|
84
|
-
mockFiles({
|
|
85
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
86
|
-
{ folder: 'actors/shopify', actorFullName: 'myteam/shopify', tokenEnvVar: 'APIFY_TOKEN' },
|
|
87
|
-
]),
|
|
88
|
-
'actors/shopify/.actor/actor.json': actorJson({ dockerContextDir: '../../..' }),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
92
|
-
expect(result[0].dockerContextDir).toBe('');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('resolves contextPaths from overrideActorContext', async () => {
|
|
96
|
-
mockFiles({
|
|
97
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
98
|
-
{
|
|
99
|
-
folder: 'actors/shopify',
|
|
100
|
-
actorFullName: 'myteam/shopify',
|
|
101
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
102
|
-
overrideActorContext: ['actors/shopify', 'packages'],
|
|
103
|
-
},
|
|
104
|
-
]),
|
|
105
|
-
'actors/shopify/.actor/actor.json': actorJson({ dockerContextDir: '../../..' }),
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
109
|
-
expect(result[0].contextPaths).toEqual(['actors/shopify', 'packages']);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('handles multiple actors', async () => {
|
|
113
|
-
mockFiles({
|
|
114
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
115
|
-
{ folder: 'actors/web-scraper', actorFullName: 'apify/web-scraper', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
116
|
-
{
|
|
117
|
-
folder: 'actors/email-sender',
|
|
118
|
-
actorFullName: 'other-team/email-sender',
|
|
119
|
-
tokenEnvVar: 'APIFY_TOKEN_OTHER_TEAM',
|
|
120
|
-
},
|
|
121
|
-
]),
|
|
122
|
-
'actors/web-scraper/.actor/actor.json': actorJson({}),
|
|
123
|
-
'actors/email-sender/.actor/actor.json': actorJson({}),
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
127
|
-
expect(result).toHaveLength(2);
|
|
128
|
-
expect(result[0].actorFullName).toBe('apify/web-scraper');
|
|
129
|
-
expect(result[1].actorFullName).toBe('other-team/email-sender');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('throws when config file is missing', async () => {
|
|
133
|
-
fsMock.readFile.mockRejectedValue(new Error('ENOENT'));
|
|
134
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('not found');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('throws when config file contains invalid JSON', async () => {
|
|
138
|
-
fsMock.readFile.mockResolvedValue('{bad json');
|
|
139
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('invalid JSON');
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('throws when actors array is missing', async () => {
|
|
143
|
-
fsMock.readFile.mockResolvedValue(JSON.stringify({ notActors: [] }));
|
|
144
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('"actors" array');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('throws on duplicate folders', async () => {
|
|
148
|
-
mockFiles({
|
|
149
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
150
|
-
{ folder: 'actors/shopify', actorFullName: 'apify/shopify', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
151
|
-
{ folder: 'actors/shopify', actorFullName: 'other/shopify', tokenEnvVar: 'APIFY_TOKEN_OTHER' },
|
|
152
|
-
]),
|
|
153
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Duplicate folder');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('throws on duplicate folders after normalization ("." and "")', async () => {
|
|
160
|
-
mockFiles({
|
|
161
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
162
|
-
{ folder: '.', actorFullName: 'apify/actor-a', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
163
|
-
{ folder: '', actorFullName: 'other/actor-b', tokenEnvVar: 'APIFY_TOKEN_OTHER' },
|
|
164
|
-
]),
|
|
165
|
-
'.actor/actor.json': actorJson({}),
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Duplicate folder');
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('throws when actor.json is missing', async () => {
|
|
172
|
-
mockFiles({
|
|
173
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
174
|
-
{ folder: 'actors/shopify', actorFullName: 'apify/shopify', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
175
|
-
]),
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Cannot read');
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('throws when folder is missing', async () => {
|
|
182
|
-
mockFiles({
|
|
183
|
-
[CONFIG_FILE_NAME]: validConfig([{ actorFullName: 'apify/shopify', tokenEnvVar: 'APIFY_TOKEN_APIFY' }]),
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow(/Invalid "folder"/);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('throws when folder is not a string', async () => {
|
|
190
|
-
mockFiles({
|
|
191
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
192
|
-
{ folder: 123, actorFullName: 'apify/shopify', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
193
|
-
]),
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow(/Invalid "folder"/);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('throws when actorFullName is missing', async () => {
|
|
200
|
-
mockFiles({
|
|
201
|
-
[CONFIG_FILE_NAME]: validConfig([{ folder: 'actors/shopify', tokenEnvVar: 'APIFY_TOKEN_APIFY' }]),
|
|
202
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Invalid "actorFullName"');
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('throws when actorFullName has no slash', async () => {
|
|
209
|
-
mockFiles({
|
|
210
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
211
|
-
{ folder: 'actors/shopify', actorFullName: 'shopify-scraper', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
212
|
-
]),
|
|
213
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Invalid "actorFullName"');
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('throws when actorFullName has empty parts', async () => {
|
|
220
|
-
mockFiles({
|
|
221
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
222
|
-
{ folder: 'actors/shopify', actorFullName: '/shopify', tokenEnvVar: 'APIFY_TOKEN_APIFY' },
|
|
223
|
-
]),
|
|
224
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Invalid "actorFullName"');
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('throws when overrideActorContext is not an array', async () => {
|
|
231
|
-
mockFiles({
|
|
232
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
233
|
-
{
|
|
234
|
-
folder: 'actors/shopify',
|
|
235
|
-
actorFullName: 'myteam/shopify',
|
|
236
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
237
|
-
overrideActorContext: 'packages',
|
|
238
|
-
},
|
|
239
|
-
]),
|
|
240
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Invalid "overrideActorContext"');
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('throws when overrideActorContext contains non-strings', async () => {
|
|
247
|
-
mockFiles({
|
|
248
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
249
|
-
{
|
|
250
|
-
folder: 'actors/shopify',
|
|
251
|
-
actorFullName: 'myteam/shopify',
|
|
252
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
253
|
-
overrideActorContext: [123],
|
|
254
|
-
},
|
|
255
|
-
]),
|
|
256
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow('Invalid "overrideActorContext"');
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('throws when overrideActorContext entries overlap (one is a prefix of another)', async () => {
|
|
263
|
-
mockFiles({
|
|
264
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
265
|
-
{
|
|
266
|
-
folder: 'actors/shopify',
|
|
267
|
-
actorFullName: 'myteam/shopify',
|
|
268
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
269
|
-
overrideActorContext: ['actors/shopify', 'actors'],
|
|
270
|
-
},
|
|
271
|
-
]),
|
|
272
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow(/overlap/);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('throws when overrideActorContext contains the repo root alongside another entry', async () => {
|
|
279
|
-
mockFiles({
|
|
280
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
281
|
-
{
|
|
282
|
-
folder: 'actors/shopify',
|
|
283
|
-
actorFullName: 'myteam/shopify',
|
|
284
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
285
|
-
overrideActorContext: ['', 'actors/shopify'],
|
|
286
|
-
},
|
|
287
|
-
]),
|
|
288
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
await expect(readConfigFile(emptyActorSelection)).rejects.toThrow(/overlap/);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('adds the actor own folder automatically when overrideActorContext does not cover it', async () => {
|
|
295
|
-
mockFiles({
|
|
296
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
297
|
-
{
|
|
298
|
-
folder: 'actors/shopify',
|
|
299
|
-
actorFullName: 'myteam/shopify',
|
|
300
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
301
|
-
overrideActorContext: ['code', 'shared'],
|
|
302
|
-
},
|
|
303
|
-
]),
|
|
304
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
308
|
-
expect(result[0].contextPaths).toEqual(['code', 'shared', 'actors/shopify']);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('strips trailing slashes from folder and overrideActorContext entries', async () => {
|
|
312
|
-
mockFiles({
|
|
313
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
314
|
-
{
|
|
315
|
-
folder: 'actors/shopify/',
|
|
316
|
-
actorFullName: 'myteam/shopify',
|
|
317
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
318
|
-
overrideActorContext: ['actors/shopify/', 'packages/'],
|
|
319
|
-
},
|
|
320
|
-
]),
|
|
321
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
325
|
-
expect(result[0].folder).toBe('actors/shopify');
|
|
326
|
-
expect(result[0].contextPaths).toEqual(['actors/shopify', 'packages']);
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it('allows overrideActorContext with disjoint sibling paths that all reach the actor folder via one entry', async () => {
|
|
330
|
-
mockFiles({
|
|
331
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
332
|
-
{
|
|
333
|
-
folder: 'actors/shopify',
|
|
334
|
-
actorFullName: 'myteam/shopify',
|
|
335
|
-
tokenEnvVar: 'APIFY_TOKEN',
|
|
336
|
-
overrideActorContext: ['actors/shopify', 'code', 'shared'],
|
|
337
|
-
},
|
|
338
|
-
]),
|
|
339
|
-
'actors/shopify/.actor/actor.json': actorJson({}),
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
const result = await readConfigFile(emptyActorSelection);
|
|
343
|
-
expect(result[0].contextPaths).toEqual(['actors/shopify', 'code', 'shared']);
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
describe('actor selection', () => {
|
|
347
|
-
const twoActors = () =>
|
|
348
|
-
mockFiles({
|
|
349
|
-
[CONFIG_FILE_NAME]: validConfig([
|
|
350
|
-
{ folder: 'actors/a', actorFullName: 'team/a', tokenEnvVar: 'TOKEN' },
|
|
351
|
-
{ folder: 'actors/b', actorFullName: 'team/b', tokenEnvVar: 'TOKEN' },
|
|
352
|
-
]),
|
|
353
|
-
'actors/a/.actor/actor.json': actorJson({}),
|
|
354
|
-
'actors/b/.actor/actor.json': actorJson({}),
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
const fullNames = (result: { actorFullName: string }[]) => result.map((c) => c.actorFullName);
|
|
358
|
-
|
|
359
|
-
it('returns all actors when the selection is empty', async () => {
|
|
360
|
-
twoActors();
|
|
361
|
-
expect(fullNames(await readConfigFile(emptyActorSelection))).toEqual(['team/a', 'team/b']);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it('keeps only the selected actors', async () => {
|
|
365
|
-
twoActors();
|
|
366
|
-
expect(fullNames(await readConfigFile({ actors: ['team/a'], ignore: [] }))).toEqual(['team/a']);
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it('drops ignored actors', async () => {
|
|
370
|
-
twoActors();
|
|
371
|
-
expect(fullNames(await readConfigFile({ actors: [], ignore: ['team/a'] }))).toEqual(['team/b']);
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it('throws on an unknown actor name', async () => {
|
|
375
|
-
twoActors();
|
|
376
|
-
await expect(readConfigFile({ actors: ['team/nope'], ignore: [] })).rejects.toThrow(
|
|
377
|
-
'do not exist: team/nope',
|
|
378
|
-
);
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
});
|