-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathPestTestIdentifier.test.ts
More file actions
92 lines (83 loc) · 4.47 KB
/
Copy pathPestTestIdentifier.test.ts
File metadata and controls
92 lines (83 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { describe, expect, it } from 'vitest';
import { TestType } from '../types';
import './PestFixer';
import { PestTestIdentifier } from './PestTestIdentifier';
describe('PestTestIdentifier', () => {
const transformer = new PestTestIdentifier();
describe('generateUniqueId', () => {
it('test /** with comment */ should do', () => {
const type = TestType.method;
const className = 'P\\Tests\\Unit\\ExampleTest';
const methodName = 'test /** with comment */ should do';
const classFQN = className;
const expected = 'tests/Unit/ExampleTest.php::test /** with comment */ should do';
expect(transformer.uniqueId({ type, classFQN, methodName })).toEqual(expected);
});
it('ensures the given closures reports the correct class name and suggests the [pest()] function', () => {
const type = TestType.method;
const className = 'P\\Tests\\Unit\\ExampleTest';
const methodName =
'ensures the given closures reports the correct class name and suggests the [pest()] function';
const classFQN = className;
const expected =
'tests/Unit/ExampleTest.php::ensures the given closures reports the correct class name and suggests the [pest()] function';
expect(transformer.uniqueId({ type, classFQN, methodName })).toEqual(expected);
});
});
describe('generateSearchText', () => {
it('test /** with comment */ should do', () => {
const input = 'test /** with comment */ should do';
const expected = 'test /\\*\\* with comment \\*/ should do';
expect(input.replace(/([[\]()*])/g, '\\$1')).toEqual(expected);
});
it('ensures the given closures reports the correct class name and suggests the [pest()] function', () => {
const input =
'ensures the given closures reports the correct class name and suggests the [pest()] function';
const expected =
'ensures the given closures reports the correct class name and suggests the \\[pest\\(\\)\\] function';
expect(input.replace(/([[\]()*])/g, '\\$1')).toEqual(expected);
});
});
describe('fromLocationHint with namespaced describe block (::class)', () => {
it.each([
[
// describe(PlaylistService::class, ...) where PlaylistService is in Foo\\Services namespace
'pest_qn://tests/Unit/PlaylistServiceTests.php::`Foo\\Services\\PlaylistService` → it does something',
'it does something',
'tests/Unit/PlaylistServiceTests.php::`Foo\\Services\\PlaylistService` → it does something',
],
])('fromLocationHint(%j, %j) → id: %s', (locationHint, name, expectedId) => {
const result = transformer.fromLocationHint(locationHint, name);
expect(result.id).toBe(expectedId);
});
});
describe('fromLocationHint v2 evaluable testSuiteStarted', () => {
it.each([
[
'file:///path/to/tests/Unit/DatasetTest.php',
'Users\\path\\to\\tests\\Unit\\DatasetTest::__pest_evaluable_it_adds_numbers',
'tests/Unit/DatasetTest.php::it adds numbers',
],
[
'file:///path/to/tests/Unit/DatasetTest.php',
'Users\\path\\to\\tests\\Unit\\DatasetTest::__pest_evaluable_it_validates_emails',
'tests/Unit/DatasetTest.php::it validates emails',
],
[
'file:///path/to/tests/Unit/DatasetTest.php',
'Users\\path\\to\\tests\\Unit\\DatasetTest::__pest_evaluable_it_business_closed',
'tests/Unit/DatasetTest.php::it business closed',
],
// describe('something', fn() => it('test', fn())->with([...]))
// v2 testSuiteStarted uses evaluable encoding with → separator
[
'file:///path/to/tests/Unit/SampleTests.php',
'Users\\path\\to\\tests\\Unit\\SampleTests::__pest_evaluable__something__\u2192_it_should_detect_OK_but_does_not',
'tests/Unit/SampleTests.php::`something` \u2192 it should detect OK but does not',
],
])('fromLocationHint(%j, %j) → id: %s', (locationHint, name, expectedId) => {
const result = transformer.fromLocationHint(locationHint, name);
expect(result.id).toBe(expectedId);
});
});
});