Skip to content

Commit e615fc9

Browse files
CopilotB4nan
andcommitted
Update tests to expect errors to be thrown instead of just logged
Co-authored-by: B4nan <615580+B4nan@users.noreply.github.com>
1 parent 212838e commit e615fc9

5 files changed

Lines changed: 22 additions & 36 deletions

File tree

test/local/__fixtures__/commands/run/python/prints-error-message-on-project-with-no-detected-start.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ describe('[python] prints error message on project with no detected start', () =
3737
});
3838

3939
it('should print error message', async () => {
40-
await testRunCommand(RunCommand, {});
41-
42-
expect(lastErrorMessage()).toMatch(/Actor is of an unknown format./i);
40+
await expect(testRunCommand(RunCommand, {})).rejects.toThrow(/Actor is of an unknown format./i);
4341
});
4442
});

test/local/commands/crawlee/run.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ describe('apify run', () => {
6363
it('throws when required field is not provided', async () => {
6464
await writeFile(inputPath, '{}');
6565

66-
await testRunCommand(RunCommand, {});
67-
68-
expect(lastErrorMessage()).toMatch(/Field awesome is required/i);
66+
await expect(testRunCommand(RunCommand, {})).rejects.toThrow(/Field awesome is required/i);
6967
});
7068

7169
it('prefills input with defaults', async () => {

test/local/commands/create.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ describe('apify create', () => {
3333

3434
['a'.repeat(151), 'sh', 'bad_escaped'].forEach((badActorName) => {
3535
it(`returns error with bad Actor name ${badActorName}`, async () => {
36-
await testRunCommand(CreateCommand, { args_actorName: badActorName });
37-
38-
expect(lastErrorMessage()).toMatch(/the actor name/i);
36+
await expect(testRunCommand(CreateCommand, { args_actorName: badActorName })).rejects.toThrow(
37+
/the actor name/i,
38+
);
3939
});
4040
});
4141

test/local/commands/run.test.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -292,45 +292,37 @@ writeFileSync(String.raw\`${joinPath('result.txt')}\`, 'hello world');
292292
writeFileSync(inputPath, '{}', { flag: 'w' });
293293
copyFileSync(missingRequiredPropertyInputSchemaPath, inputSchemaPath);
294294

295-
await testRunCommand(RunCommand, {});
296-
297-
expect(lastErrorMessage()).toMatch(/Field awesome is required/i);
295+
await expect(testRunCommand(RunCommand, {})).rejects.toThrow(/Field awesome is required/i);
298296
});
299297

300298
it('throws when required field has wrong type', async () => {
301299
writeFileSync(inputPath, '{"awesome": 42}', { flag: 'w' });
302300
copyFileSync(defaultsInputSchemaPath, inputSchemaPath);
303301

304-
await testRunCommand(RunCommand, {});
305-
306-
expect(lastErrorMessage()).toMatch(/Field awesome must be boolean/i);
302+
await expect(testRunCommand(RunCommand, {})).rejects.toThrow(/Field awesome must be boolean/i);
307303
});
308304

309305
it('throws when passing manual input, but local file has correct input', async () => {
310306
writeFileSync(inputPath, '{"awesome": true}', { flag: 'w' });
311307
copyFileSync(defaultsInputSchemaPath, inputSchemaPath);
312308

313-
await testRunCommand(RunCommand, { flags_input: handPassedInput });
314-
315-
expect(lastErrorMessage()).toMatch(/Field awesome must be boolean/i);
309+
await expect(testRunCommand(RunCommand, { flags_input: handPassedInput })).rejects.toThrow(
310+
/Field awesome must be boolean/i,
311+
);
316312
});
317313

318314
it('throws when input has default field of wrong type', async () => {
319315
writeFileSync(inputPath, '{"awesome": true, "help": 123}', { flag: 'w' });
320316
copyFileSync(defaultsInputSchemaPath, inputSchemaPath);
321317

322-
await testRunCommand(RunCommand, {});
323-
324-
expect(lastErrorMessage()).toMatch(/Field help must be string/i);
318+
await expect(testRunCommand(RunCommand, {})).rejects.toThrow(/Field help must be string/i);
325319
});
326320

327321
it('throws when input has prefilled field of wrong type', async () => {
328322
writeFileSync(inputPath, '{"awesome": true, "help": 123}', { flag: 'w' });
329323
copyFileSync(prefillsInputSchemaPath, inputSchemaPath);
330324

331-
await testRunCommand(RunCommand, {});
332-
333-
expect(lastErrorMessage()).toMatch(/Field help must be string/i);
325+
await expect(testRunCommand(RunCommand, {})).rejects.toThrow(/Field help must be string/i);
334326
});
335327

336328
it('automatically inserts missing defaulted fields', async () => {

test/local/commands/validate-schema.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ describe('apify validate-schema', () => {
1919
});
2020

2121
it('should correctly validate schema 2', async () => {
22-
await testRunCommand(ValidateInputSchemaCommand, {
23-
args_path: invalidInputSchemaPath,
24-
});
25-
26-
expect(lastErrorMessage()).to.contain(
27-
'Field schema.properties.queries.editor must be equal to one of the allowed values',
28-
);
22+
await expect(
23+
testRunCommand(ValidateInputSchemaCommand, {
24+
args_path: invalidInputSchemaPath,
25+
}),
26+
).rejects.toThrow(/Field schema.properties.queries.editor must be equal to one of the allowed values/);
2927
});
3028

3129
it('should correctly validate schema 3', async () => {
32-
await testRunCommand(ValidateInputSchemaCommand, {
33-
args_path: unparsableInputSchemaPath,
34-
});
35-
36-
expect(lastErrorMessage()).to.contain.oneOf(['Unexpected token }', "Expected ',' or ']' after array element"]);
30+
await expect(
31+
testRunCommand(ValidateInputSchemaCommand, {
32+
args_path: unparsableInputSchemaPath,
33+
}),
34+
).rejects.toThrow();
3735
});
3836
});

0 commit comments

Comments
 (0)