Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(testing): update test regex for 'e2e.ts' #3277

Merged
merged 2 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/compiler/config/test/validate-testing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ describe('validateTesting', () => {
expect(testRegex.test('my-component.test.jsx')).toBe(true);
});

it('matches the file "test.ts"', () => {
expect(testRegex.test('some/path/test.ts')).toBe(true);
});

it('matches the file "test.tsx"', () => {
expect(testRegex.test('some/path/test.tsx')).toBe(true);
});

it('matches the file "test.js"', () => {
expect(testRegex.test('some/path/test.js')).toBe(true);
});

it('matches the file "test.jsx"', () => {
expect(testRegex.test('some/path/test.jsx')).toBe(true);
});

it("doesn't match files ending in test.ts", () => {
expect(testRegex.test('my-component-test.ts')).toBe(false);
});
Expand Down Expand Up @@ -201,6 +217,22 @@ describe('validateTesting', () => {
expect(testRegex.test('my-component.spec.jsx')).toBe(true);
});

it('matches the file "spec.ts"', () => {
expect(testRegex.test('some/path/spec.ts')).toBe(true);
});

it('matches the file "spec.tsx"', () => {
expect(testRegex.test('some/path/spec.tsx')).toBe(true);
});

it('matches the file "spec.js"', () => {
expect(testRegex.test('some/path/spec.js')).toBe(true);
});

it('matches the file "spec.jsx"', () => {
expect(testRegex.test('some/path/spec.jsx')).toBe(true);
});

it("doesn't match files ending in spec.ts", () => {
expect(testRegex.test('my-component-spec.ts')).toBe(false);
});
Expand Down Expand Up @@ -243,6 +275,22 @@ describe('validateTesting', () => {
expect(testRegex.test('my-component.e2e.jsx')).toBe(true);
});

it('matches the file "e2e.ts"', () => {
expect(testRegex.test('some/path/e2e.ts')).toBe(true);
});

it('matches the file "e2e.tsx"', () => {
expect(testRegex.test('some/path/e2e.tsx')).toBe(true);
});

it('matches the file "e2e.js"', () => {
expect(testRegex.test('some/path/e2e.js')).toBe(true);
});

it('matches the file "e2e.jsx"', () => {
expect(testRegex.test('some/path/e2e.jsx')).toBe(true);
});

it("doesn't match files ending in e2e.ts", () => {
expect(testRegex.test('my-component-e2e.ts')).toBe(false);
});
Expand Down
13 changes: 12 additions & 1 deletion src/compiler/config/validate-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,18 @@ export const validateTesting = (config: d.Config, diagnostics: d.Diagnostic[]) =
}

if (testing.testRegex === undefined) {
testing.testRegex = '(/__tests__/.*|\\.(test|spec|e2e))\\.(tsx|ts|jsx|js)$';
/**
* The test regex covers cases of:
* - files under a `__tests__` directory
* - the case where a test file has a name such as `test.ts`, `spec.ts` or `e2e.ts`.
* - these files can use any of the following file extensions: .ts, .tsx, .js, .jsx.
* - this regex only handles the entire path of a file, e.g. `/some/path/e2e.ts`
* - the case where a test file ends with `.test.ts`, `.spec.ts`, or `.e2e.ts`.
* - these files can use any of the following file extensions: .ts, .tsx, .js, .jsx.
* - this regex case shall match file names such as `my-cmp.spec.ts`, `test.spec.ts`
* - this regex case shall not match file names such as `attest.ts`, `bespec.ts`
*/
testing.testRegex = '(/__tests__/.*|(\\.|/)(test|spec|e2e))\\.[jt]sx?';
}

if (Array.isArray(testing.testMatch)) {
Expand Down