Skip to content

Commit

Permalink
Merge pull request #153 from testomatio/jest-fix
Browse files Browse the repository at this point in the history
fix unusual case for jest
  • Loading branch information
olexandr13 committed Mar 13, 2024
2 parents be151c3 + ed4c052 commit a52245c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/lib/frameworks/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
}

if (path.isIdentifier({ name: 'beforeEach' })) {
beforeEachCode = getCode(source, getLineNumber(path.parentPath), getEndLineNumber(path.parentPath), isLineNumber);
beforeEachCode = getCode(
source,
getLineNumber(path.parentPath),
getEndLineNumber(path.parentPath),
isLineNumber,
);
}

if (path.isIdentifier({ name: 'afterAll' })) {
Expand All @@ -63,9 +68,9 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
if (['describe', 'it', 'context', 'test'].includes(name)) {
const line = getLineNumber(path);
throw new CommentError(
'Exclusive tests detected. `.only` call found in '
+ `${file}:${line}\n`
+ 'Remove `.only` to restore test checks',
'Exclusive tests detected. `.only` call found in ' +
`${file}:${line}\n` +
'Remove `.only` to restore test checks',
);
}
}
Expand All @@ -75,7 +80,7 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
return;
}

const name = path.parent.object.name || path.parent.object.callee.object.name;
const name = path.parent.object?.name || path.parent.object?.callee?.object?.name;

if (name === 'test' || name === 'it') {
// test or it
Expand Down Expand Up @@ -132,10 +137,10 @@ module.exports = (ast, file = '', source = '', opts = {}) => {

code = noHooks
? getCode(source, getLineNumber(path), getEndLineNumber(path), isLineNumber)
: beforeEachCode
+ beforeCode
+ getCode(source, getLineNumber(path), getEndLineNumber(path), isLineNumber)
+ afterCode;
: beforeEachCode +
beforeCode +
getCode(source, getLineNumber(path), getEndLineNumber(path), isLineNumber) +
afterCode;

const testName = getStringValue(path.parent);
tests.push({
Expand Down

0 comments on commit a52245c

Please sign in to comment.