Skip to content

Commit

Permalink
chore: use output.{fmt}.js for exports-fixture assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Jun 4, 2021
1 parent 64d799f commit 491826b
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/fixtures/exports-named-list/output.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function foo(a) {
return a + a;
}

const bar = b => b + b;

async function baz(a) {
return a + a;
}

let hello = 'world';

var abc = 123;

class Foo extends Component {
//
}



exports.Foo = Foo;
exports.abc = abc;
exports.bar = bar;
exports.baz = baz;
exports.foo = foo;
exports.hello = hello;
File renamed without changes.
24 changes: 24 additions & 0 deletions test/fixtures/exports-named/output.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function foo(a) {
return a + a;
}

const bar = b => b + b;

async function baz(a) {
return a + a;
}

let hello = 'world';

var abc = 123;

class Foo extends Component {
//
}

exports.Foo = Foo;
exports.abc = abc;
exports.bar = bar;
exports.baz = baz;
exports.foo = foo;
exports.hello = hello;
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions test/fixtures/exports-strings/expects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cjs": "dist/basic.js"
}
26 changes: 26 additions & 0 deletions test/fixtures/exports-strings/output.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function hello() {
return 'import{foo}from"bar";export const bar = foo + 123;';
}

function world() {
return "export { foo } from 'foobar'";
}

function there() {
return 'var foo=123;export default foo';
}

const hiya = true;

let foo=1, bar=2, foobar=3;




exports.bar = bar;
exports.foo = foo;
exports.foobar = foobar;
exports.hello = hello;
exports.hiya = hiya;
exports.there = there;
exports.world = world;
3 changes: 3 additions & 0 deletions test/fixtures/exports-strings/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "basic"
}
18 changes: 18 additions & 0 deletions test/fixtures/exports-strings/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function hello() {
return 'import{foo}from"bar";export const bar = foo + 123;';
}

export function world() {
return "export { foo } from 'foobar'";
}

export function there() {
return 'var foo=123;export default foo';
}

export const hiya = true;

let foo=1, bar=2, foobar=3;

export{ foo, bar };
export { foobar };
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ fs.readdirSync(fixtures).forEach(dirname => {
let data = fs.readFileSync(file, 'utf8');
assert.ok(tests[k].test(data), `(${k}) ~> contents look right`);

let output = join(dir, `output.${k}.js`);
if (fs.existsSync(output)) {
output = fs.readFileSync(output, 'utf8');
assert.fixture(
data.trim(),
output.trim()
);
}

if (k === 'cjs') {
assert.not.throws(() => new Function(data), SyntaxError);
} else if (k === 'umd' && 'name' in expects) {
Expand Down

0 comments on commit 491826b

Please sign in to comment.