Skip to content

Commit

Permalink
fix(testing): handle snapshot filepaths (#3282)
Browse files Browse the repository at this point in the history
this commit updates the testing regex in our jest base configuration to
handle files such as testing snapshots - those that contain 'spec.ts'
(or a similarly acceptable file extension for tests), but do not end
with that extension. For example, `my-component.test.ts.snap`

this fixes a regression introduced in cf42114
  • Loading branch information
rwaskiewicz committed Mar 16, 2022
1 parent 9514a69 commit d164dba
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
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 @@ -175,6 +175,22 @@ describe('validateTesting', () => {
expect(testRegex.test('some/path/test.jsx')).toBe(true);
});

it("doesn't match snap files ending in test.ts.snap", () => {
expect(testRegex.test('my-component.test.ts.snap')).toBe(false);
});

it("doesn't match snap files ending in test.tsx.snap", () => {
expect(testRegex.test('my-component.test.tsx.snap')).toBe(false);
});

it("doesn't match snap files ending in test.js.snap", () => {
expect(testRegex.test('my-component.test.js.snap')).toBe(false);
});

it("doesn't match snap files ending in test.jsx.snap", () => {
expect(testRegex.test('my-component.test.jsx.snap')).toBe(false);
});

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

it("doesn't match snap files ending in spec.ts.snap", () => {
expect(testRegex.test('my-component.spec.ts.snap')).toBe(false);
});

it("doesn't match snap files ending in spec.tsx.snap", () => {
expect(testRegex.test('my-component.spec.tsx.snap')).toBe(false);
});

it("doesn't match snap files ending in spec.js.snap", () => {
expect(testRegex.test('my-component.spec.js.snap')).toBe(false);
});

it("doesn't match snap files ending in spec.jsx.snap", () => {
expect(testRegex.test('my-component.spec.jsx.snap')).toBe(false);
});

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

it("doesn't match snap files ending in e2e.ts.snap", () => {
expect(testRegex.test('my-component.e2e.ts.snap')).toBe(false);
});

it("doesn't match snap files ending in e2e.tsx.snap", () => {
expect(testRegex.test('my-component.e2e.tsx.snap')).toBe(false);
});

it("doesn't match snap files ending in e2e.js.snap", () => {
expect(testRegex.test('my-component.e2e.js.snap')).toBe(false);
});

it("doesn't match snap files ending in e2e.jsx.snap", () => {
expect(testRegex.test('my-component.e2e.jsx.snap')).toBe(false);
});

it("doesn't match files ending in e2e.ts", () => {
expect(testRegex.test('my-component-e2e.ts')).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/config/validate-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const validateTesting = (config: d.Config, diagnostics: d.Diagnostic[]) =
* - 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?';
testing.testRegex = '(/__tests__/.*|(\\.|/)(test|spec|e2e))\\.[jt]sx?$';
}

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

0 comments on commit d164dba

Please sign in to comment.