Skip to content

Commit

Permalink
Fix/quasi params (#162)
Browse files Browse the repository at this point in the history
* added validation for test titles

* fixed quasi strings
  • Loading branch information
DavertMik committed Jul 1, 2024
1 parent 8a59f30 commit 0f1e687
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/lib/frameworks/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,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 Down Expand Up @@ -137,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
20 changes: 9 additions & 11 deletions src/lib/frameworks/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,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 @@ -88,8 +88,7 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
return;
}

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

if (name === 'test' || name === 'it') {
// test or it
Expand Down Expand Up @@ -124,8 +123,7 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
return;
}

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

if (name === 'test' || name === 'it') {
// test or it
Expand Down Expand Up @@ -189,10 +187,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);

Expand Down
6 changes: 3 additions & 3 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ function getQuasiArgument(path) {
for (const node of nodes) {
if (node.type === 'MemberExpression') {
if (node.property && node.property.type === 'Identifier') {
quasiValue += ' ${' + node.property.name + '} '; // eslint-disable-line prefer-template
quasiValue += '${' + node.property.name + '}'; // eslint-disable-line prefer-template
continue;
}
}
if (node.type === 'Identifier') {
quasiValue += ' ${' + node.name + '} '; // eslint-disable-line prefer-template
quasiValue += '${' + node.name + '}'; // eslint-disable-line prefer-template
continue;
}
if (!node.value) continue;
if (node.value.raw) quasiValue += node.value.raw.trim();
if (node.value.raw) quasiValue += node.value.raw;
}

return quasiValue;
Expand Down
16 changes: 16 additions & 0 deletions tests/playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ describe('playwright parser', () => {
expect(tests[4].tags).to.have.all.members(['smoke', 'regression', 'windows']);
});
});
it('should parse playwright-ts tests with params', () => {
source = fs.readFileSync('./example/playwright/params.ts').toString();
const program = tsParser.parse(source, {
sourceType: 'unambiguous',
loc: true,
range: true,
tokens: true,
});
ast = {
program,
type: 'File',
};
const tests = playwrightParser(ast, '', source);

expect(tests[0].name).to.equal('check ${i} on "${pageUrl}" page');
});

it('should parse playwright-js tests with annotation', () => {
source = fs.readFileSync('./example/playwright/annotations.js').toString();
Expand Down

0 comments on commit 0f1e687

Please sign in to comment.