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: handle skipped test correctly #24

Merged
merged 1 commit into from
Nov 27, 2019
Merged
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
9 changes: 5 additions & 4 deletions lib/path-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function parseTestFile(paths, path, data) {
if (paths[path] == undefined) {
paths[path] = { describe: [], it: [] };
}
if (type === 'describe') {
if (type.includes("describe")) {
paths[path].describe.push(text);
}
if (type === 'it') {
if (type.includes("it")) {
paths[path].it.push(text);
}
}
Expand Down Expand Up @@ -60,7 +60,8 @@ function existIt(paths, path, it) {
}

function regexPattern() {
return /((describe)|(it))\s*\(\s*((?<![\\])[\`\'\"])((?:.(?!(?<![\\])\4))*.?)\4/gi;
// https://regex101.com/r/HUyh3u/1
return /((\S{0,2}describe?[^(]+)|(\s\S{0,2}it?[^(]+))\s*\(\s*((?<![\\])[`'"])((?:.(?!(?<![\\])\4))*.?)\4/gi;
}

function removeEscapedQuotes(str) {
Expand All @@ -78,4 +79,4 @@ function removeNewLines(data) {
module.exports = {
parseTestFiles: parseTestFiles,
testFile: testFile
};
};
32 changes: 28 additions & 4 deletions spec/lib/path-finder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const testFileData = {
'describe(\'s7.2\', function() { it(\'d7.2\', function() {}); });' +
'describe(\'s7.3\', function() { it(\'d7.3\', function() {}); });' +
'describe(\'s7.4\', function() { describe(\'s7.4.1\'+\'text\', function() { ' +
'it(\'d7.4.1\'+\'text\', function() {}); }); });'
'it(\'d7.4.1\'+\'text\', function() {}); }); });',
'path/t8.spec.js': 'describe.skip(\'s8\', function() { it.skip(\'d8\', function() {}); });',
'path/t9.spec.js':'describe(\'s9\', function() { xit(\'d9.1\', function() {}); });' +
'describe(\'s9.2\', function() { it.skip(\'d9.2\', function() {}); });' +
'describe(\'s9.3\', function() { xit(\'d9.3\', function() {}); });' +
'describe(\'s9.4\', function() { describe.skip(\'s9.4.1\'+\'text\', function() { ' +
'fit(\'d9.4.1\'+\'text\', function() {}); }); });',
}

const parsedTestFiles = {
Expand All @@ -24,7 +30,11 @@ const parsedTestFiles = {
'path/t5.spec.js': { describe: ['\\\"s5\\\"'], it: ['\\\"d5\\\"']},
'path/t6.spec.js': { describe: ['s6\"\\\\\'\\\\\'\"'], it: ['d6\"\\\\\'\\\\\'\"']},
'path/t7.spec.js': { describe: ['s7', 's7.2', 's7.3', 's7.4', 's7.4.1'],
it: ['d7.1', 'd7.2', 'd7.3', 'd7.4.1']}
it: ['d7.1', 'd7.2', 'd7.3', 'd7.4.1']},
'path/t8.spec.js': { describe: ['s8'], it: ['d8'] },
'path/t9.spec.js': { describe: ['s9', 's9.2', 's9.3', 's9.4', 's9.4.1'],
it: ['d9.1', 'd9.2', 'd9.3', 'd9.4.1'],
}
}

describe('Path finder tests', function() {
Expand Down Expand Up @@ -88,11 +98,17 @@ describe('Path finder tests', function() {
expect(path.it[1]).toBe('d3.2');
});

it("8st test file match suite 8 and description 8 with skipped suite and test", function() {
var paths = pathFinder.parseTestFiles("**/*.spec.ts", "utf-8");
var path = paths["path/t8.spec.js"];
expect(path.describe[0]).toBe("s8");
expect(path.it[0]).toBe("d8");
});

describe('Test cases with quoted text', function() {
it('4rd test file match suite and description with single quotes', function() {
var paths = pathFinder.parseTestFiles('**/*.spec.ts', 'utf-8');
var path = paths['path/t4.spec.js'];
console.log()
expect(path.describe[0]).toBe('\\\'s4\\\'');
expect(path.it[0]).toBe('\\\'d4\\\'');
});
Expand Down Expand Up @@ -141,6 +157,14 @@ describe('Path finder tests', function() {
expect(path.describe[4]).toBe('s7.4.1');
expect(path.it[3]).toBe('d7.4.1');
});

it("9st test file match suite 9 and description 9 with skipped test", function() {
var paths = pathFinder.parseTestFiles("**/*.spec.ts", "utf-8");
var path = paths["path/t9.spec.js"];
expect(path.describe[0]).toBe("s9");
expect(path.it[0]).toBe("d9.1");
expect(path.it[1]).toBe("d9.2");
});
});
});

Expand Down Expand Up @@ -192,4 +216,4 @@ describe('Path finder tests', function() {
expect(pathFinder.testFile(parsedTestFiles, 's7.4.1text', 'd7.4.1text')).toBe('path/t7.spec.js');
});
});
});
});