-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f738e9
commit fc08341
Showing
9 changed files
with
131 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const { test } = require('tap') | ||
const Range = require('../../classes/range') | ||
const SemVer = require('../../classes/semver') | ||
const Comparator = require('../../classes/comparator') | ||
const validRange = require('../../ranges/valid') | ||
const minVersion = require('../../ranges/min-version') | ||
const minSatisfying = require('../../ranges/min-satisfying') | ||
const maxSatisfying = require('../../ranges/max-satisfying') | ||
|
||
const s = (n = 500000) => ' '.repeat(n) | ||
|
||
test('regex dos via range whitespace', (t) => { | ||
// a range with this much whitespace would take a few minutes to process if | ||
// any redos susceptible regexes were used. there is a global tap timeout per | ||
// file set in the package.json that will error if this test takes too long. | ||
const r = `1.2.3 ${s()} <1.3.0` | ||
|
||
t.equal(new Range(r).range, '1.2.3 <1.3.0') | ||
t.equal(validRange(r), '1.2.3 <1.3.0') | ||
t.equal(minVersion(r).version, '1.2.3') | ||
t.equal(minSatisfying(['1.2.3'], r), '1.2.3') | ||
t.equal(maxSatisfying(['1.2.3'], r), '1.2.3') | ||
|
||
t.end() | ||
}) | ||
|
||
test('semver version', (t) => { | ||
const v = `${s(125)}1.2.3${s(125)}` | ||
const tooLong = `${s()}1.2.3${s()}` | ||
t.equal(new SemVer(v).version, '1.2.3') | ||
t.throws(() => new SemVer(tooLong)) | ||
t.end() | ||
}) | ||
|
||
test('comparator', (t) => { | ||
const c = `${s()}<${s()}1.2.3${s()}` | ||
t.equal(new Comparator(c).value, '<1.2.3') | ||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,46 @@ | ||
const t = require('tap') | ||
const { resolve, join, relative, extname, dirname, basename } = require('path') | ||
const { statSync, readdirSync } = require('fs') | ||
const map = require('../map.js') | ||
const pkg = require('../package.json') | ||
|
||
// ensure that the coverage map maps all coverage | ||
const ignore = [ | ||
'.git', | ||
'.github', | ||
'.commitlintrc.js', | ||
'.eslintrc.js', | ||
'.eslintrc.local.js', | ||
'node_modules', | ||
'coverage', | ||
'tap-snapshots', | ||
'test', | ||
'fixtures', | ||
] | ||
const ROOT = resolve(__dirname, '..') | ||
const TEST = join(ROOT, 'test') | ||
const IGNORE_DIRS = ['fixtures', 'integration'] | ||
|
||
const { statSync, readdirSync } = require('fs') | ||
const find = (folder, set = [], root = true) => { | ||
const ent = readdirSync(folder) | ||
set.push(...ent.filter(f => !ignore.includes(f) && /\.m?js$/.test(f)).map(f => folder + '/' + f)) | ||
for (const e of ent.filter(f => !ignore.includes(f) && !/\.m?js$/.test(f))) { | ||
if (statSync(folder + '/' + e).isDirectory()) { | ||
find(folder + '/' + e, set, false) | ||
const getFile = (f) => { | ||
try { | ||
if (statSync(f).isFile()) { | ||
return extname(f) === '.js' ? [f] : [] | ||
} | ||
} catch { | ||
return [] | ||
} | ||
if (!root) { | ||
return | ||
} | ||
return set.map(f => f.slice(folder.length + 1) | ||
.replace(/\\/g, '/')) | ||
.sort((a, b) => a.localeCompare(b)) | ||
} | ||
|
||
const { resolve } = require('path') | ||
const root = resolve(__dirname, '..') | ||
const walk = (item, res = []) => getFile(item) || readdirSync(item) | ||
.map(f => join(item, f)) | ||
.reduce((acc, f) => acc.concat(statSync(f).isDirectory() ? walk(f, res) : getFile(f)), []) | ||
.filter(Boolean) | ||
|
||
const sut = find(root) | ||
const tests = find(root + '/test') | ||
t.strictSame(sut, tests, 'test files should match system files') | ||
const map = require('../map.js') | ||
const walkAll = (items, relativeTo) => items | ||
.reduce((acc, f) => acc.concat(walk(join(ROOT, f))), []) | ||
.map((f) => relative(relativeTo, f)) | ||
.sort() | ||
|
||
for (const testFile of tests) { | ||
t.test(testFile, t => { | ||
t.plan(1) | ||
// cast to an array, since map() can return a string or array | ||
const systemFiles = [].concat(map(testFile)) | ||
t.ok(systemFiles.some(sys => sut.includes(sys)), 'test covers a file') | ||
}) | ||
} | ||
t.test('tests match system', t => { | ||
const sut = walkAll([pkg.tap['coverage-map'], ...pkg.files], ROOT) | ||
const tests = walkAll([basename(TEST)], TEST) | ||
.filter(f => !IGNORE_DIRS.includes(dirname(f))) | ||
|
||
t.strictSame(sut, tests, 'test files should match system files') | ||
|
||
for (const f of tests) { | ||
t.test(f, t => { | ||
t.plan(1) | ||
t.ok(sut.includes(map(f)), 'test covers a file') | ||
}) | ||
} | ||
|
||
t.end() | ||
}) |