From 8d56752956cdee7a7f32dcf59a5f1193989e8a9e Mon Sep 17 00:00:00 2001 From: Kael Zhang Date: Mon, 19 Dec 2022 22:20:27 +0800 Subject: [PATCH] #57: test: support test.only --- test/fixtures/cases.js | 46 ++++++++++++++++++++++++++++++++++++------ test/ignore.js | 18 ++++++++++++----- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/test/fixtures/cases.js b/test/fixtures/cases.js index d94aaf1..bcd4b14 100644 --- a/test/fixtures/cases.js +++ b/test/fixtures/cases.js @@ -22,6 +22,38 @@ const cases = [ // } // ], ///////////////////////////////////////////////////////////////////// + [ + 'charactor ?', + [ + 'foo?bar' + ], + { + 'foo/bar': 0, + 'fooxbar': 1, + 'fooxxbar': 0 + } + ], + [ + '#57, normal * and normal consecutive *', + [ + '**foo', + '*bar', + 'ba*z' + ], + { + 'foo': 1, + 'a/foo': 1, + 'afoo': 1, + 'abfoo': 1, + 'abcfoo': 1, + 'bar': 1, + 'abar': 1, + 'baz': 1, + 'ba/z': 0, + 'baaaaaaz': 1 + }, + true + ], [ '#76 (invalid), comments with no heading whitespace', [ @@ -992,12 +1024,13 @@ const real_cases = cases_to_test_only.length : cases exports.cases = iteratee => { - real_cases.forEach(c => { - const description = c[0] - const patterns = c[1] - const paths_object = c[2] - const skip_test_fixture = c[4] - + real_cases.forEach(([ + description, + patterns, + paths_object, + test_only, + skip_test_fixture + ]) => { // All paths to test const paths = Object.keys(paths_object) @@ -1018,6 +1051,7 @@ exports.cases = iteratee => { description, patterns, paths_object, + test_only, skip_test_fixture, paths, expected, diff --git a/test/ignore.js b/test/ignore.js index dfdbe89..0bbf688 100755 --- a/test/ignore.js +++ b/test/ignore.js @@ -1,4 +1,7 @@ -const {test} = require('tap') +const { + test, + only +} = require('tap') const ignore = require('..') const { @@ -13,11 +16,16 @@ cases(({ description, patterns, paths_object, + test_only, paths, expect_result }) => { + const tt = test_only + ? only + : test + checkEnv('IGNORE_ONLY_FILTER') - && test(`.filter(): ${description}`, t => { + && tt(`.filter(): ${description}`, t => { const ig = ignore() const result = ig .addPattern(patterns) @@ -28,7 +36,7 @@ cases(({ }) checkEnv('IGNORE_ONLY_CREATE_FILTER') - && test(`.createFilter(): ${description}`, t => { + && tt(`.createFilter(): ${description}`, t => { const result = paths.filter( ignore() .addPattern(patterns) @@ -42,7 +50,7 @@ cases(({ }) checkEnv('IGNORE_ONLY_IGNORES') - && test(`.ignores(path): ${description}`, t => { + && tt(`.ignores(path): ${description}`, t => { const ig = ignore().addPattern(patterns) Object.keys(paths_object).forEach(path => { @@ -56,7 +64,7 @@ cases(({ } checkEnv('IGNORE_ONLY_WIN32') - && test(`win32: .filter(): ${description}`, t => { + && tt(`win32: .filter(): ${description}`, t => { const win_paths = paths.map(make_win32) const ig = ignore()