Description: switch test from ava+tsc to tape (common JS) Author: Yadd Forwarded: not-needed Last-Update: 2022-10-10 --- a/packages/pluginutils/test/addExtension.ts +++ b/packages/pluginutils/test/addExtension.ts @@ -1,26 +1,31 @@ -import test from 'ava'; +import test from 'tape'; -import { addExtension } from '../'; +import { addExtension } from '@rollup/pluginutils'; test('adds .js to an ID without an extension', (t) => { t.is(addExtension('foo'), 'foo.js'); + t.end(); }); test('ignores file with existing extension', (t) => { t.is(addExtension('foo.js'), 'foo.js'); t.is(addExtension('foo.json'), 'foo.json'); + t.end(); }); test('ignores file with trailing dot', (t) => { t.is(addExtension('foo.'), 'foo.'); + t.end(); }); test('ignores leading .', (t) => { t.is(addExtension('./foo'), './foo.js'); t.is(addExtension('./foo.js'), './foo.js'); + t.end(); }); test('adds a custom extension', (t) => { t.is(addExtension('foo', '.wut'), 'foo.wut'); t.is(addExtension('foo.lol', '.wut'), 'foo.lol'); + t.end(); }); --- a/packages/pluginutils/test/attachScopes.ts +++ b/packages/pluginutils/test/attachScopes.ts @@ -1,24 +1,26 @@ import * as estree from 'estree'; -import test from 'ava'; +import test from 'tape'; import { parse } from 'acorn'; -import { attachScopes, AttachedScope } from '../'; +import { attachScopes, AttachedScope } from '@rollup/pluginutils'; test('attaches a scope to the top level', (t) => { const ast = parse('var foo;', { ecmaVersion: 2020, sourceType: 'module' }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('foo')); - t.falsy(scope.contains('bar')); + t.ok(scope.contains('foo')); + t.notOk(scope.contains('bar')); + t.end(); }); test('adds multiple declarators from a single var declaration', (t) => { const ast = parse('var foo, bar;', { ecmaVersion: 2020, sourceType: 'module' }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('foo')); - t.truthy(scope.contains('bar')); + t.ok(scope.contains('foo')); + t.ok(scope.contains('bar')); + t.end(); }); test('adds named declarators from a deconstructed declaration', (t) => { @@ -28,8 +30,9 @@ }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('a')); - t.truthy(scope.contains('b')); + t.ok(scope.contains('a')); + t.ok(scope.contains('b')); + t.end(); }); test('adds rest elements from a deconstructed object declaration', (t) => { @@ -39,10 +42,11 @@ }); const scope = attachScopes(ast, 'scope'); - t.truthy(scope.contains('x')); - t.falsy(scope.contains('y')); - t.truthy(scope.contains('z')); - t.truthy(scope.contains('rest')); + t.ok(scope.contains('x')); + t.notOk(scope.contains('y')); + t.ok(scope.contains('z')); + t.ok(scope.contains('rest')); + t.end(); }); test('adds nested declarators from a deconstructed declaration', (t) => { @@ -52,25 +56,28 @@ }); const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); - t.truthy(scope.contains('c')); + t.notOk(scope.contains('a')); + t.notOk(scope.contains('b')); + t.ok(scope.contains('c')); + t.end(); }); test('supports FunctionDeclarations without id', (t) => { const ast = parse('export default function () {}', { ecmaVersion: 2020, sourceType: 'module' }); - t.notThrows(() => { + t.doesNotThrow(() => { attachScopes(ast, 'scope'); }); + t.end(); }); test('supports catch without a parameter', (t) => { const ast = parse('try {} catch {}', { ecmaVersion: 2020, sourceType: 'script' }); - t.notThrows(() => { + t.doesNotThrow(() => { attachScopes(ast, 'scope'); }); + t.end(); }); test('supports ForStatement', (t) => { @@ -85,17 +92,18 @@ ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); + t.notOk(scope.contains('a')); + t.notOk(scope.contains('b')); const forLoop = ast.body[0] as estree.ForStatement & { scope: AttachedScope }; - t.truthy(forLoop.scope.contains('a')); - t.falsy(forLoop.scope.contains('b')); + t.ok(forLoop.scope.contains('a')); + t.notOk(forLoop.scope.contains('b')); const forBody = forLoop.body as estree.BlockStatement & { scope: AttachedScope }; - t.truthy(forBody.scope.contains('a')); - t.truthy(forBody.scope.contains('b')); + t.ok(forBody.scope.contains('a')); + t.ok(forBody.scope.contains('b')); + t.end(); }); test('supports ForOfStatement', (t) => { @@ -110,16 +118,17 @@ ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); + t.notOk(scope.contains('a')); + t.notOk(scope.contains('b')); const forLoop = ast.body[0] as estree.ForOfStatement & { scope: AttachedScope }; - t.truthy(forLoop.scope.contains('a')); - t.falsy(forLoop.scope.contains('b')); + t.ok(forLoop.scope.contains('a')); + t.notOk(forLoop.scope.contains('b')); const forBody = forLoop.body as estree.BlockStatement & { scope: AttachedScope }; - t.truthy(forBody.scope.contains('a')); - t.truthy(forBody.scope.contains('b')); + t.ok(forBody.scope.contains('a')); + t.ok(forBody.scope.contains('b')); + t.end(); }); test('supports ForInStatement', (t) => { @@ -134,14 +143,15 @@ ) as unknown as estree.Program; const scope = attachScopes(ast, 'scope'); - t.falsy(scope.contains('a')); - t.falsy(scope.contains('b')); + t.notOk(scope.contains('a')); + t.notOk(scope.contains('b')); const forLoop = ast.body[0] as estree.ForInStatement & { scope: AttachedScope }; - t.truthy(forLoop.scope.contains('a')); - t.falsy(forLoop.scope.contains('b')); + t.ok(forLoop.scope.contains('a')); + t.notOk(forLoop.scope.contains('b')); const forBody = forLoop.body as estree.BlockStatement & { scope: AttachedScope }; - t.truthy(forBody.scope.contains('a')); - t.truthy(forBody.scope.contains('b')); + t.ok(forBody.scope.contains('a')); + t.ok(forBody.scope.contains('b')); + t.end(); }); --- a/packages/pluginutils/test/createFilter.ts +++ b/packages/pluginutils/test/createFilter.ts @@ -1,156 +1,183 @@ import { resolve as rawResolve } from 'path'; -import test from 'ava'; +import test from 'tape'; -import { createFilter, normalizePath } from '../'; +import { createFilter, normalizePath } from '@rollup/pluginutils'; const resolve = (...parts: string[]) => normalizePath(rawResolve(...parts)); -test.beforeEach(() => process.chdir(__dirname)); - test('includes by default', (t) => { + process.chdir(__dirname); const filter = createFilter(); - t.truthy(filter(resolve('x'))); + t.ok(filter(resolve('x'))); + t.end(); }); test('excludes IDs that are not included, if include.length > 0', (t) => { + process.chdir(__dirname); const filter = createFilter(['y']); - t.falsy(filter(resolve('x'))); - t.truthy(filter(resolve('y'))); + t.notOk(filter(resolve('x'))); + t.ok(filter(resolve('y'))); + t.end(); }); test('excludes IDs explicitly', (t) => { + process.chdir(__dirname); const filter = createFilter(null, ['y']); - t.truthy(filter(resolve('x'))); - t.falsy(filter(resolve('y'))); + t.ok(filter(resolve('x'))); + t.notOk(filter(resolve('y'))); + t.end(); }); test('handles non-array arguments', (t) => { + process.chdir(__dirname); const filter = createFilter('foo/*', 'foo/baz'); - t.truthy(filter(resolve('foo/bar'))); - t.falsy(filter(resolve('foo/baz'))); + t.ok(filter(resolve('foo/bar'))); + t.notOk(filter(resolve('foo/baz'))); + t.end(); }); test('negation patterns', (t) => { + process.chdir(__dirname); const filter = createFilter(['a/!(b)/c']); - t.truthy(filter(resolve('a/d/c'))); - t.falsy(filter(resolve('a/b/c'))); + t.ok(filter(resolve('a/d/c'))); + t.notOk(filter(resolve('a/b/c'))); + t.end(); }); test('excludes non-string IDs', (t) => { + process.chdir(__dirname); const filter = createFilter(null, null); - t.falsy(filter({})); + t.notOk(filter({})); + t.end(); }); test('excludes strings beginning with NUL', (t) => { + process.chdir(__dirname); const filter = createFilter(null, null); - t.falsy(filter('\0someid')); + t.notOk(filter('\0someid')); + t.end(); }); test('includes with regexp', (t) => { + process.chdir(__dirname); const filter = createFilter(['a/!(b)/c', /\.js$/]); - t.truthy(filter(resolve('a/d/c'))); - t.falsy(filter(resolve('a/b/c'))); - t.truthy(filter(resolve('a.js'))); - t.truthy(filter(resolve('a/b.js'))); - t.falsy(filter(resolve('a/b.jsx'))); + t.ok(filter(resolve('a/d/c'))); + t.notOk(filter(resolve('a/b/c'))); + t.ok(filter(resolve('a.js'))); + t.ok(filter(resolve('a/b.js'))); + t.notOk(filter(resolve('a/b.jsx'))); + t.end(); }); test('excludes with regexp', (t) => { + process.chdir(__dirname); const filter = createFilter(['a/!(b)/c', /\.js$/], /\.js$/); - t.truthy(filter(resolve('a/d/c'))); - t.falsy(filter(resolve('a/b/c'))); - t.falsy(filter(resolve('a.js'))); - t.falsy(filter(resolve('a/b.js'))); - t.falsy(filter(resolve('a/b.jsx'))); + t.ok(filter(resolve('a/d/c'))); + t.notOk(filter(resolve('a/b/c'))); + t.notOk(filter(resolve('a.js'))); + t.notOk(filter(resolve('a/b.js'))); + t.notOk(filter(resolve('a/b.jsx'))); + t.end(); }); test('allows setting an absolute base dir', (t) => { + process.chdir(__dirname); const baseDir = resolve('C'); const filter = createFilter(['y*'], ['yx'], { resolve: baseDir }); - t.falsy(filter(`${baseDir}/x`)); - t.truthy(filter(`${baseDir}/ys`)); - t.falsy(filter(`${baseDir}/yx`)); - t.falsy(filter(resolve('C/d/ys'))); - t.falsy(filter(resolve('ys'))); - t.falsy(filter('ys')); + t.notOk(filter(`${baseDir}/x`)); + t.ok(filter(`${baseDir}/ys`)); + t.notOk(filter(`${baseDir}/yx`)); + t.notOk(filter(resolve('C/d/ys'))); + t.notOk(filter(resolve('ys'))); + t.notOk(filter('ys')); + t.end(); }); test('allows setting a relative base dir', (t) => { + process.chdir(__dirname); const filter = createFilter(['y*'], ['yx'], { resolve: 'C/d' }); - t.falsy(filter(resolve('C/d/x'))); - t.truthy(filter(resolve('C/d/ys'))); - t.falsy(filter(resolve('C/d/yx'))); - t.falsy(filter(`${resolve('C')}/ys`)); - t.falsy(filter(resolve('ys'))); - t.falsy(filter('ys')); + t.notOk(filter(resolve('C/d/x'))); + t.ok(filter(resolve('C/d/ys'))); + t.notOk(filter(resolve('C/d/yx'))); + t.notOk(filter(`${resolve('C')}/ys`)); + t.notOk(filter(resolve('ys'))); + t.notOk(filter('ys')); + t.end(); }); -test('ignores a falsy resolve value', (t) => { +test('ignores a notOk resolve value', (t) => { + process.chdir(__dirname); const filter = createFilter(['y*'], ['yx'], { resolve: null }); - t.falsy(filter(resolve('x'))); - t.truthy(filter(resolve('ys'))); - t.falsy(filter(resolve('yx'))); - t.falsy(filter(`${resolve('C')}/ys`)); - t.falsy(filter(resolve('C/d/ys'))); - t.falsy(filter('ys')); + t.notOk(filter(resolve('x'))); + t.ok(filter(resolve('ys'))); + t.notOk(filter(resolve('yx'))); + t.notOk(filter(`${resolve('C')}/ys`)); + t.notOk(filter(resolve('C/d/ys'))); + t.notOk(filter('ys')); + t.end(); }); test('allows preventing resolution against process.cwd()', (t) => { + process.chdir(__dirname); const filter = createFilter(['y*'], ['yx'], { resolve: false }); - t.falsy(filter('x')); - t.truthy(filter('ys')); - t.falsy(filter('yx')); - t.falsy(filter(`${resolve('C')}/ys`)); - t.falsy(filter(resolve('C/d/ys'))); - t.falsy(filter(resolve('ys'))); + t.notOk(filter('x')); + t.ok(filter('ys')); + t.notOk(filter('yx')); + t.notOk(filter(`${resolve('C')}/ys`)); + t.notOk(filter(resolve('C/d/ys'))); + t.notOk(filter(resolve('ys'))); + t.end(); }); test('includes names starting with a "."', (t) => { + process.chdir(__dirname); const filter = createFilter(['**/*a']); - t.truthy(filter(resolve('.a'))); - t.truthy(filter(resolve('.x/a'))); -}); - -test.serial('includes names containing parenthesis', (t) => { - process.chdir(resolve(__dirname, 'fixtures/folder-with (parens)')); - const filter = createFilter(['*.ts+(|x)', '**/*.ts+(|x)'], ['*.d.ts', '**/*.d.ts']); - t.truthy(filter(resolve('folder (test)/src/main.tsx'))); - t.truthy(filter(resolve('.x/(test)a.ts'))); - t.falsy(filter(resolve('.x/(test)a.d.ts'))); + t.ok(filter(resolve('.a'))); + t.ok(filter(resolve('.x/a'))); + t.end(); }); test('handles relative paths', (t) => { + process.chdir(__dirname); const filter = createFilter(['./index.js', './foo/../a.js']); - t.truthy(filter(resolve('index.js'))); - t.truthy(filter(resolve('a.js'))); - t.falsy(filter(resolve('foo/a.js'))); + t.ok(filter(resolve('index.js'))); + t.ok(filter(resolve('a.js'))); + t.notOk(filter(resolve('foo/a.js'))); + t.end(); }); test('does not add current working directory when pattern is an absolute path', (t) => { + process.chdir(__dirname); const filter = createFilter([resolve('..', '..', '*')]); - t.truthy(filter(resolve('..', '..', 'a'))); - t.truthy(filter(resolve('..', '..', 'b'))); - t.falsy(filter(resolve('..', 'c'))); + t.ok(filter(resolve('..', '..', 'a'))); + t.ok(filter(resolve('..', '..', 'b'))); + t.notOk(filter(resolve('..', 'c'))); + t.end(); }); test('normalizes path when pattern is an absolute path', (t) => { + process.chdir(__dirname); const filterPosix = createFilter([`${resolve('.')}/*`]); const filterWin = createFilter([`${resolve('.')}\\*`]); - t.truthy(filterPosix(resolve('a'))); - t.truthy(filterWin(resolve('a'))); + t.ok(filterPosix(resolve('a'))); + t.ok(filterWin(resolve('a'))); + t.end(); }); test('normalizes path when pattern starts with *', (t) => { + process.chdir(__dirname); const filterPosix = createFilter([`**/a`]); const filterWin = createFilter([`**\\a`]); - t.truthy(filterPosix(resolve('a'))); - t.truthy(filterWin(resolve('a'))); + t.ok(filterPosix(resolve('a'))); + t.ok(filterWin(resolve('a'))); + t.end(); }); test('normalizes path when pattern has resolution base', (t) => { + process.chdir(__dirname); const filterPosix = createFilter([`test/*`], [], { resolve: __dirname }); @@ -158,12 +185,15 @@ resolve: __dirname }); - t.truthy(filterPosix(resolve('test/a'))); - t.truthy(filterWin(resolve('test/a'))); + t.ok(filterPosix(resolve('test/a'))); + t.ok(filterWin(resolve('test/a'))); + t.end(); }); test('does not add current working directory when pattern starts with a glob', (t) => { + process.chdir(__dirname); const filter = createFilter(['**/*']); - t.truthy(filter(resolve('a'))); - t.truthy(filter(resolve('..', '..', 'a'))); + t.ok(filter(resolve('a'))); + t.ok(filter(resolve('..', '..', 'a'))); + t.end(); }); --- a/packages/pluginutils/test/dataToEsm.ts +++ b/packages/pluginutils/test/dataToEsm.ts @@ -1,12 +1,13 @@ -import test from 'ava'; +import test from 'tape'; -import { dataToEsm } from '../'; +import { dataToEsm } from '@rollup/pluginutils'; test('support bigint', (t) => { t.is( dataToEsm({ positive: BigInt('0'), negative: BigInt('-1') }), 'export var positive = 0n;\nexport var negative = -1n;\nexport default {\n\tpositive: positive,\n\tnegative: negative\n};\n' ); + t.end(); }); test('support symbol', (t) => { @@ -14,6 +15,7 @@ dataToEsm({ normal: Symbol.for('key'), empty: Symbol.for('') }), 'export var normal = Symbol.for("key");\nexport var empty = Symbol.for("");\nexport default {\n\tnormal: normal,\n\tempty: empty\n};\n' ); + t.end(); }); test('outputs treeshakeable data', (t) => { @@ -21,6 +23,7 @@ dataToEsm({ some: 'data', another: 'data' }), 'export var some = "data";\nexport var another = "data";\nexport default {\n\tsome: some,\n\tanother: another\n};\n' ); + t.end(); }); test('handles illegal identifiers, object shorthand, preferConst', (t) => { @@ -28,6 +31,7 @@ dataToEsm({ '1': 'data', default: 'data' }, { objectShorthand: true, preferConst: true }), 'export default {\n\t"1": "data",\n\t"default": "data"\n};\n' ); + t.end(); }); test('supports non-JSON data', (t) => { @@ -36,6 +40,7 @@ dataToEsm({ inf: -Infinity, date, number: NaN, regexp: /.*/ }), `export var inf = -Infinity;\nexport var date = new Date(${date.getTime()});\nexport var number = NaN;\nexport var regexp = /.*/;\nexport default {\n\tinf: inf,\n\tdate: date,\n\tnumber: number,\n\tregexp: regexp\n};\n` ); + t.end(); }); test('supports a compact argument', (t) => { @@ -53,6 +58,7 @@ ), 'export var some={deep:{object:"definition",here:"here"}};export default{some:some,"else":{deep:{object:"definition",here:"here"}}};' ); + t.end(); }); test('supports nested objects', (t) => { @@ -61,6 +67,7 @@ dataToEsm({ obj }), 'export var obj = {\n\ta: {\n\t\tb: "c",\n\t\td: [\n\t\t\t"e",\n\t\t\t"f"\n\t\t]\n\t}\n};\nexport default {\n\tobj: obj\n};\n' ); + t.end(); }); test('supports nested arrays', (t) => { @@ -69,10 +76,12 @@ dataToEsm({ arr }), 'export var arr = [\n\t"a",\n\t"b"\n];\nexport default {\n\tarr: arr\n};\n' ); + t.end(); }); test('serializes null', (t) => { t.is(dataToEsm({ null: null }), 'export default {\n\t"null": null\n};\n'); + t.end(); }); test('supports default only', (t) => { @@ -81,19 +90,23 @@ dataToEsm({ arr }, { namedExports: false }), 'export default {\n\tarr: [\n\t\t"a",\n\t\t"b"\n\t]\n};' ); + t.end(); }); test('exports default only for arrays', (t) => { const arr = ['a', 'b']; t.is(dataToEsm(arr), 'export default [\n\t"a",\n\t"b"\n];'); + t.end(); }); test('exports default only for null', (t) => { t.is(dataToEsm(null, { compact: true }), 'export default null;'); + t.end(); }); test('exports default only for primitive values', (t) => { t.is(dataToEsm('some string'), 'export default "some string";'); + t.end(); }); test('supports empty keys', (t) => { @@ -101,6 +114,7 @@ dataToEsm({ a: 'x', '': 'y' }), 'export var a = "x";\nexport default {\n\ta: a,\n\t"": "y"\n};\n' ); + t.end(); }); test('avoid U+2029 U+2029 -0 be ignored by JSON.stringify, and avoid it return non-string (undefined) before replacing', (t) => { @@ -109,4 +123,5 @@ dataToEsm([-0, '\u2028\u2029', undefined, function () {}], { compact: true }), 'export default[-0,"\\u2028\\u2029",undefined,undefined];' ); + t.end(); }); --- a/packages/pluginutils/test/extractAssignedNames.ts +++ b/packages/pluginutils/test/extractAssignedNames.ts @@ -1,6 +1,6 @@ -import test from 'ava'; +import test from 'tape'; -import { extractAssignedNames } from '../'; +import { extractAssignedNames } from '@rollup/pluginutils'; test('extracts an Identifier', (t) => { const node = { @@ -11,6 +11,7 @@ }; t.deepEqual(extractAssignedNames(node), ['x']); + t.end(); }); test('extracts from array patterns', (t) => { @@ -71,6 +72,7 @@ }; t.deepEqual(extractAssignedNames(node), ['a', 'b', 'd', 'e']); + t.end(); }); test('extracts from object patterns', (t) => { @@ -212,6 +214,7 @@ }; t.deepEqual(extractAssignedNames(node), ['a', 'c', 'f', 'h', 'i']); + t.end(); }); test('ignores updated member expressions', (t) => { @@ -260,4 +263,5 @@ }; t.deepEqual(extractAssignedNames(node), []); + t.end(); }); --- a/packages/pluginutils/test/makeLegalIdentifier.ts +++ b/packages/pluginutils/test/makeLegalIdentifier.ts @@ -1,23 +1,28 @@ -import test from 'ava'; +import test from 'tape'; -import { makeLegalIdentifier } from '../'; +import { makeLegalIdentifier } from '@rollup/pluginutils'; test('camel-cases names', (t) => { t.is(makeLegalIdentifier('foo-bar'), 'fooBar'); + t.end(); }); test('replaces keywords', (t) => { t.is(makeLegalIdentifier('typeof'), '_typeof'); + t.end(); }); test('blacklists arguments (https://github.com/rollup/rollup/issues/871)', (t) => { t.is(makeLegalIdentifier('arguments'), '_arguments'); + t.end(); }); test('empty', (t) => { t.is(makeLegalIdentifier(''), '_'); + t.end(); }); test('handles input evaluated to blacklisted identifier', (t) => { t.is(makeLegalIdentifier('parse-int'), '_parseInt'); + t.end(); }); --- a/packages/pluginutils/test/normalizePath.ts +++ b/packages/pluginutils/test/normalizePath.ts @@ -1,17 +1,20 @@ -import test from 'ava'; +import test from 'tape'; -import { normalizePath } from '../'; +import { normalizePath } from '@rollup/pluginutils'; test('replaces \\ with /', (t) => { t.is(normalizePath('foo\\bar'), 'foo/bar'); t.is(normalizePath('foo\\bar\\baz'), 'foo/bar/baz'); + t.end(); }); test('ignores forward slash', (t) => { t.is(normalizePath('foo/bar'), 'foo/bar'); t.is(normalizePath('foo/bar\\baz'), 'foo/bar/baz'); + t.end(); }); test('handles empty string', (t) => { t.is(normalizePath(''), ''); + t.end(); });