Skip to content

fix oneline tests are not parsed #1

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions dist/jest-parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* jest-parser v1.1.0
* (c) 2021-2021 Martin Rafael Gonzalez <tin@devtin.io>
* (c) 2021-2022 Martin Rafael Gonzalez <tin@devtin.io>
* MIT
*/
'use strict';
Expand Down Expand Up @@ -57,7 +57,11 @@ const unIndentString = (str) => {
};

const getCodeBlockPattern = (fnName) => {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2[^{]*{[\\n](.*?)[\\n]}\\)`, 'gims')
if (fnName === 'it') {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2`, 'gims')
} else {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2[^{]*{[\\n](.*?)[\\n]}\\)`, 'gims')
}
};

const getFnBlockedContent = (source, fnNames = []) => {
Expand Down
8 changes: 6 additions & 2 deletions dist/jest-parser.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* jest-parser v1.1.0
* (c) 2021-2021 Martin Rafael Gonzalez <tin@devtin.io>
* (c) 2021-2022 Martin Rafael Gonzalez <tin@devtin.io>
* MIT
*/
/**
Expand Down Expand Up @@ -53,7 +53,11 @@ const unIndentString = (str) => {
};

const getCodeBlockPattern = (fnName) => {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2[^{]*{[\\n](.*?)[\\n]}\\)`, 'gims')
if (fnName === 'it') {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2`, 'gims')
} else {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2[^{]*{[\\n](.*?)[\\n]}\\)`, 'gims')
}
};

const getFnBlockedContent = (source, fnNames = []) => {
Expand Down
77 changes: 67 additions & 10 deletions src/lib/__tests__/__snapshots__/parse.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ describe.only('Nested describe 1', () => {
"flag": "only",
"it": Array [
Object {
"code": "// code of what it does
expect(true).toBeTruthy()",
"code": "",
"describe": Array [],
"end": 3,
"end": -1,
"flag": undefined,
"it": Array [],
"start": 0,
"start": -1,
"title": "does this and that",
},
],
Expand Down Expand Up @@ -62,7 +61,35 @@ expect(true).toBeTruthy()",
"title": "Some describe title 3",
},
],
"it": Array [],
"it": Array [
Object {
"code": "",
"describe": Array [],
"end": -1,
"flag": undefined,
"it": Array [],
"start": -1,
"title": "one line explicit-return arrow function",
},
Object {
"code": "",
"describe": Array [],
"end": -1,
"flag": undefined,
"it": Array [],
"start": -1,
"title": "one line implicit-return arrow function",
},
Object {
"code": "",
"describe": Array [],
"end": -1,
"flag": undefined,
"it": Array [],
"start": -1,
"title": "multiline implicit-return arrow function",
},
],
}
`;

Expand All @@ -89,13 +116,12 @@ describe.only('Nested describe 1', () => {
"flag": "only",
"it": Array [
Object {
"code": "// code of what it does
expect(true).toBeTruthy()",
"code": "",
"describe": Array [],
"end": 3,
"end": -1,
"flag": undefined,
"it": Array [],
"start": 0,
"start": -1,
"test": Array [],
"title": "does this and that",
},
Expand Down Expand Up @@ -133,7 +159,38 @@ expect(true).toBeTruthy()",
"title": "Some describe title 3",
},
],
"it": Array [],
"it": Array [
Object {
"code": "",
"describe": Array [],
"end": -1,
"flag": undefined,
"it": Array [],
"start": -1,
"test": Array [],
"title": "one line explicit-return arrow function",
},
Object {
"code": "",
"describe": Array [],
"end": -1,
"flag": undefined,
"it": Array [],
"start": -1,
"test": Array [],
"title": "one line implicit-return arrow function",
},
Object {
"code": "",
"describe": Array [],
"end": -1,
"flag": undefined,
"it": Array [],
"start": -1,
"test": Array [],
"title": "multiline implicit-return arrow function",
},
],
"test": Array [],
"title": "Some jest file",
}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/__tests__/fixtures/jest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ describe('Some describe title 2', () => {
describe('Some describe title 3', () => {
// some code 3
})

it('one line explicit-return arrow function', () => { return Promise.resolve(true) })
it('one line implicit-return arrow function', () => Promise.resolve(true))
it('multiline implicit-return arrow function', () =>
Promise.resolve(true)
)
6 changes: 5 additions & 1 deletion src/lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export const unIndentString = (str) => {
}

export const getCodeBlockPattern = (fnName) => {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2[^{]*{[\\n](.*?)[\\n]}\\)`, 'gims')
if (fnName === 'it') {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2`, 'gims')
} else {
return new RegExp(`^${fnName}(?:\\.([a-z]+))?\\((["'\`])(.*?)\\2[^{]*{[\\n](.*?)[\\n]}\\)`, 'gims')
}
}

export const getFnBlockedContent = (source, fnNames = []) => {
Expand Down