Skip to content

Commit

Permalink
Expand Test Coverage (#262)
Browse files Browse the repository at this point in the history
* functions exported with arguments

* Test for strict removal

* Test for removing strict declaration on mjs output when the output is an iife.
  • Loading branch information
kristoferbaxter authored Dec 28, 2019
1 parent c2a4295 commit 81c79be
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/export-named/fixtures/multiple.esm.advanced.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
function bar(){console.log(1)};var foo=1;export{bar,foo};
function bar(){console.log(1)};function baz(a){console.log(a)};var foo=1;export{bar,baz,foo};
2 changes: 1 addition & 1 deletion test/export-named/fixtures/multiple.esm.default.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
function bar(){console.log(1)};var foo=1;export{bar,foo};
function bar(){console.log(1)};function baz(a){console.log(a)};var foo=1;export{bar,baz,foo};
2 changes: 1 addition & 1 deletion test/export-named/fixtures/multiple.esm.es5.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
function bar(){console.log(1)};var foo=1;export{bar,foo};
function bar(){console.log(1)};function baz(a){console.log(a)};var foo=1;export{bar,baz,foo};
5 changes: 4 additions & 1 deletion test/export-named/fixtures/multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ const foo = 1;
const bar = function() {
console.log(foo);
}
export{foo, bar};
const baz = function(name) {
console.log(name);
}
export{foo, bar, baz};
1 change: 1 addition & 0 deletions test/strict-removal/fixtures/mjs-suffix.iife.default.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var modular=function(a){a.thing=1;return a}({});
3 changes: 3 additions & 0 deletions test/strict-removal/fixtures/mjs-suffix.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

export const thing = 1;
1 change: 1 addition & 0 deletions test/strict-removal/fixtures/top-level.esm.advanced.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var thing=1;
1 change: 1 addition & 0 deletions test/strict-removal/fixtures/top-level.esm.default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var thing=1;
1 change: 1 addition & 0 deletions test/strict-removal/fixtures/top-level.esm.es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export var thing=1;
3 changes: 3 additions & 0 deletions test/strict-removal/fixtures/top-level.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

export const thing = 1;
55 changes: 55 additions & 0 deletions test/strict-removal/mjs-suffix.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const test = require('ava');
const { default: compiler } = require('../../transpile/index');
const rollup = require('rollup');
const fs = require('fs');
const path = require('path');

test('remove strict declaration from .mjs input', async t => {
const bundle = await rollup.rollup({
input: 'test/strict-removal/fixtures/mjs-suffix.mjs',
plugins: [compiler()],
onwarn: _ => null,
});

const bundles = await bundle.generate({
format: 'iife',
name: 'modular',
sourcemap: true,
file: 'mjs-suffix.iife.default.mjs'
});

const output = [];
if (bundles.output) {
for (const file in bundles.output) {
const minified = await fs.promises.readFile(
path.join('test/strict-removal/fixtures/mjs-suffix.iife.default.mjs'),
'utf8',
);
output.push({
minified,
code: bundles.output[file].code,
});
}
}

t.plan(output.length);
for (const result of output) {
t.is(result.code, result.minified);
}
});
19 changes: 19 additions & 0 deletions test/strict-removal/top-level.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {generator} from '../generator';

generator('strict-removal', 'top-level');

0 comments on commit 81c79be

Please sign in to comment.