Browse Source

add a boatload of tests from es6-module-transpiler

contingency-plan
Rich Harris 10 years ago
parent
commit
652eca9f1e
  1. 5
      test/samples/bindings/_config.js
  2. 5
      test/samples/bindings/foo.js
  3. 5
      test/samples/bindings/main.js
  4. 6
      test/samples/custom-path-resolver-async/_config.js
  5. 6
      test/samples/custom-path-resolver-sync/_config.js
  6. 5
      test/samples/cycles-defaults/_config.js
  7. 3
      test/samples/cycles-defaults/a.js
  8. 3
      test/samples/cycles-defaults/b.js
  9. 7
      test/samples/cycles-defaults/main.js
  10. 5
      test/samples/cycles-immediate/_config.js
  11. 18
      test/samples/cycles-immediate/evens.js
  12. 22
      test/samples/cycles-immediate/main.js
  13. 16
      test/samples/cycles-immediate/odds.js
  14. 5
      test/samples/default-export-is-not-bound/_config.js
  15. 12
      test/samples/default-export-is-not-bound/foo.js
  16. 6
      test/samples/default-export-is-not-bound/main.js
  17. 10
      test/samples/duplicate-import-fails/_config.js
  18. 1
      test/samples/duplicate-import-fails/foo.js
  19. 4
      test/samples/duplicate-import-fails/main.js
  20. 10
      test/samples/duplicate-import-specifier-fails/_config.js
  21. 1
      test/samples/duplicate-import-specifier-fails/foo.js
  22. 2
      test/samples/duplicate-import-specifier-fails/main.js
  23. 3
      test/samples/empty-imports-have-side-effects/_config.js
  24. 1
      test/samples/empty-imports-have-side-effects/foo.js
  25. 3
      test/samples/empty-imports-have-side-effects/main.js
  26. 6
      test/samples/export-deconflicted-names/_config.js
  27. 5
      test/samples/export-from-default/_config.js
  28. 1
      test/samples/export-from-default/first.js
  29. 2
      test/samples/export-from-default/main.js
  30. 1
      test/samples/export-from-default/second.js
  31. 6
      test/samples/export-from-internal-module/_config.js
  32. 11
      test/samples/export-from-no-local-binding/_config.js
  33. 1
      test/samples/export-from-no-local-binding/first.js
  34. 2
      test/samples/export-from-no-local-binding/main.js
  35. 5
      test/samples/export-from-no-local-binding/second.js
  36. 8
      test/samples/export-not-at-top-level-fails/_config.js
  37. 3
      test/samples/export-not-at-top-level-fails/main.js
  38. 6
      test/samples/exports-named-values/_config.js
  39. 5
      test/samples/import-as/_config.js
  40. 5
      test/samples/import-as/foo.js
  41. 5
      test/samples/import-as/main.js
  42. 5
      test/samples/import-chain/_config.js
  43. 1
      test/samples/import-chain/first.js
  44. 2
      test/samples/import-chain/main.js
  45. 2
      test/samples/import-chain/second.js
  46. 5
      test/samples/import-default-and-named-function/_config.js
  47. 7
      test/samples/import-default-and-named-function/foo.js
  48. 4
      test/samples/import-default-and-named-function/main.js
  49. 5
      test/samples/import-default-as-named/_config.js
  50. 3
      test/samples/import-default-as-named/foo.js
  51. 6
      test/samples/import-default-as-named/main.js
  52. 6
      test/samples/import-default-class/_config.js
  53. 4
      test/samples/import-default-class/main.js
  54. 6
      test/samples/import-default-class/point.js
  55. 6
      test/samples/import-named-class/_config.js
  56. 2
      test/samples/import-named-class/foo.js
  57. 3
      test/samples/import-named-class/main.js
  58. 6
      test/samples/import-nameless-class-expression/_config.js
  59. 1
      test/samples/import-nameless-class-expression/foo.js
  60. 3
      test/samples/import-nameless-class-expression/main.js
  61. 8
      test/samples/import-not-at-top-level-fails/_config.js
  62. 3
      test/samples/import-not-at-top-level-fails/index.js
  63. 10
      test/samples/namespace-reassign-import-fails/_config.js
  64. 1
      test/samples/namespace-reassign-import-fails/foo.js
  65. 3
      test/samples/namespace-reassign-import-fails/main.js
  66. 10
      test/samples/namespace-update-import-fails/_config.js
  67. 1
      test/samples/namespace-update-import-fails/foo.js
  68. 3
      test/samples/namespace-update-import-fails/main.js
  69. 5
      test/samples/namespaces/_config.js
  70. 3
      test/samples/namespaces/foo.js
  71. 11
      test/samples/namespaces/main.js
  72. 5
      test/samples/re-export-default-import/_config.js
  73. 3
      test/samples/re-export-default-import/first.js
  74. 2
      test/samples/re-export-default-import/main.js
  75. 2
      test/samples/re-export-default-import/second.js
  76. 5
      test/samples/re-export-namespace-import/_config.js
  77. 2
      test/samples/re-export-namespace-import/first.js
  78. 4
      test/samples/re-export-namespace-import/main.js
  79. 2
      test/samples/re-export-namespace-import/second.js
  80. 10
      test/samples/reassign-import-fails/_config.js
  81. 1
      test/samples/reassign-import-fails/foo.js
  82. 8
      test/samples/reassign-import-fails/main.js
  83. 10
      test/samples/reassign-import-not-at-top-level-fails/_config.js
  84. 1
      test/samples/reassign-import-not-at-top-level-fails/foo.js
  85. 8
      test/samples/reassign-import-not-at-top-level-fails/main.js
  86. 5
      test/samples/shadowed-variables/_config.js
  87. 1
      test/samples/shadowed-variables/foo.js
  88. 9
      test/samples/shadowed-variables/main.js
  89. 3
      test/samples/this-is-undefined/_config.js
  90. 1
      test/samples/this-is-undefined/main.js
  91. 10
      test/samples/update-expression-of-import-fails/_config.js
  92. 1
      test/samples/update-expression-of-import-fails/foo.js
  93. 3
      test/samples/update-expression-of-import-fails/main.js
  94. 61
      test/test.js

5
test/samples/bindings/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'maintains live bindings'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/bindings

5
test/samples/bindings/foo.js

@ -0,0 +1,5 @@
export var count = 0;
export function incr() {
count++;
}

5
test/samples/bindings/main.js

@ -0,0 +1,5 @@
import { count, incr } from './foo';
assert.equal (count, 0 );
incr();
assert.equal( count, 1 );

6
test/samples/custom-path-resolver-async/_config.js

@ -1,3 +1,5 @@
var assert = require( 'assert' );
module.exports = {
description: 'uses a custom path resolver (synchronous)',
options: {
@ -14,7 +16,7 @@ module.exports = {
return Promise.resolve( resolved );
}
},
exports: function ( exports, assert ) {
exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) );
}
};
};

6
test/samples/custom-path-resolver-sync/_config.js

@ -1,3 +1,5 @@
var assert = require( 'assert' );
module.exports = {
description: 'uses a custom path resolver (synchronous)',
options: {
@ -9,7 +11,7 @@ module.exports = {
return false;
}
},
exports: function ( exports, assert ) {
exports: function ( exports ) {
assert.strictEqual( exports.path, require( 'path' ) );
}
};
};

5
test/samples/cycles-defaults/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'cycles work with default exports'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/cycles-defaults

3
test/samples/cycles-defaults/a.js

@ -0,0 +1,3 @@
import b from './b';
export default { a: 1, get b() { return b.b; } };

3
test/samples/cycles-defaults/b.js

@ -0,0 +1,3 @@
import a from './a';
export default { b: 2, get a() { return a.a; } };

7
test/samples/cycles-defaults/main.js

@ -0,0 +1,7 @@
import a from './a';
import b from './b';
assert.equal( a.a, 1 );
assert.equal( a.b, 2 );
assert.equal( b.a, 1 );
assert.equal( b.b, 2 );

5
test/samples/cycles-immediate/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'handles cycles where imports are immediately used'
};
// Test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/cycles-immediate

18
test/samples/cycles-immediate/evens.js

@ -0,0 +1,18 @@
import { nextOdd } from './odds';
/**
* We go through these gymnastics to eager-bind to nextOdd. This is done to
* ensure that both this module and the 'odds' module eagerly use something
* from the other.
*/
export var nextEven = (function() {
return function(n) {
var no = nextOdd(n);
return (no === n + 2) ?
no - 1 : no;
};
})(nextOdd);
export function isEven(n) {
return n % 2 === 0;
}

22
test/samples/cycles-immediate/main.js

@ -0,0 +1,22 @@
import { nextEven, isEven } from './evens';
import { nextOdd, isOdd } from './odds';
/**
* The 'evens' and 'odds' modules are configured in such a way that they both
* have two exported functions: isEven, nextEven, isOdd, and nextOdd. Normally
* these four functions could be in any order regardless of which depends on
* which because of JavaScript function hoisting.
*
* For the purposes of our test we need to prevent function hoisting, so it has
* been arranged that two of them will be function expressions assigned to
* variables. Specifically, isOdd and nextEven both eagerly evaluate their
* dependencies (i.e. isEven and nextOdd). This allows us to test that exported
* function declarations are available before what would be a module's
* "execute" step, per the spec.
*/
assert.equal(nextEven(1), 2);
assert.equal(nextOdd(1), 3);
assert.ok(isOdd(1));
assert.ok(!isOdd(0));
assert.ok(isEven(0));
assert.ok(!isEven(1));

16
test/samples/cycles-immediate/odds.js

@ -0,0 +1,16 @@
import { isEven } from './evens';
export function nextOdd(n) {
return isEven(n) ? n + 1 : n + 2;
}
/**
* We go through these gymnastics to eager-bind to isEven. This is done to
* ensure that both this module and the 'evens' module eagerly use something
* from the other.
*/
export var isOdd = (function(isEven) {
return function(n) {
return !isEven(n);
};
})(isEven);

5
test/samples/default-export-is-not-bound/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'does not bind default exports'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default

12
test/samples/default-export-is-not-bound/foo.js

@ -0,0 +1,12 @@
var a = 42;
export function change() {
a++;
}
export default a;
// Any replacement for the `export default` above needs to happen in the same
// location. It cannot be done, say, at the end of the file. Otherwise the new
// value of `a` will be used and will be incorrect.
a = 0;

6
test/samples/default-export-is-not-bound/main.js

@ -0,0 +1,6 @@
import value from './foo';
import { change } from './foo';
assert.equal(value, 42);
change();
assert.equal( value, 42, 'default export should not be bound' );

10
test/samples/duplicate-import-fails/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows duplicate imports',
error: function ( err ) {
assert.ok( false ); // TK - pick an error message
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/duplicate-import-fails

1
test/samples/duplicate-import-fails/foo.js

@ -0,0 +1 @@
export var a = 1;

4
test/samples/duplicate-import-fails/main.js

@ -0,0 +1,4 @@
import { a } from './foo';
import { a } from './foo';
assert.equal(a, 1);

10
test/samples/duplicate-import-specifier-fails/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows duplicate import specifiers',
error: function ( err ) {
assert.ok( false ); // TK - pick an error message
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/duplicate-import-specifier-fails

1
test/samples/duplicate-import-specifier-fails/foo.js

@ -0,0 +1 @@
export var a = 1;

2
test/samples/duplicate-import-specifier-fails/main.js

@ -0,0 +1,2 @@
import { a, a } from './exporter';
assert.equal(a, 1);

3
test/samples/empty-imports-have-side-effects/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'empty imports are assumed to contain side-effects'
};

1
test/samples/empty-imports-have-side-effects/foo.js

@ -0,0 +1 @@
global.answer = 42;

3
test/samples/empty-imports-have-side-effects/main.js

@ -0,0 +1,3 @@
import './foo';
assert.equal( global.answer, 42 );

6
test/samples/export-deconflicted-names/_config.js

@ -1,6 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'correctly exports deconflicted names',
exports: function ( exports, assert ) {
exports: function ( exports ) {
assert.equal( exports.bar(), 'bar' );
}
};
};

5
test/samples/export-from-default/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'export from works with default exports'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-from-default

1
test/samples/export-from-default/first.js

@ -0,0 +1 @@
export default 1;

2
test/samples/export-from-default/main.js

@ -0,0 +1,2 @@
import a from './second';
assert.equal(a, 1);

1
test/samples/export-from-default/second.js

@ -0,0 +1 @@
export { default } from './first';

6
test/samples/export-from-internal-module/_config.js

@ -1,6 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'exports from an internal module',
exports: function ( exports, assert ) {
exports: function ( exports ) {
assert.equal( exports.foo, 42 );
}
};
};

11
test/samples/export-from-no-local-binding/_config.js

@ -0,0 +1,11 @@
var assert = require( 'assert' );
module.exports = {
description: 'export from does not create a local binding',
error: function () {
assert.ok( false, 'TODO: assertion is skipped because it is not used... we need to implement something like /*rollup: include */')
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-from

1
test/samples/export-from-no-local-binding/first.js

@ -0,0 +1 @@
export var a = 1;

2
test/samples/export-from-no-local-binding/main.js

@ -0,0 +1,2 @@
import { a } from './second';
assert.equal(a, 1);

5
test/samples/export-from-no-local-binding/second.js

@ -0,0 +1,5 @@
export { a } from './first';
// This `a` reference should not be re-written because this export is not
// creating a local binding.
assert.equal(typeof a, 'undefined');

8
test/samples/export-not-at-top-level-fails/_config.js

@ -0,0 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows non-top-level exports',
error: function ( err ) {
assert.ok( false, 'TODO: pick an error message' );
}
};

3
test/samples/export-not-at-top-level-fails/main.js

@ -0,0 +1,3 @@
function foo() {
export { foo };
}

6
test/samples/exports-named-values/_config.js

@ -1,6 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'exports named values from the bundle entry module',
exports: function ( exports, assert ) {
exports: function ( exports ) {
assert.equal( exports.answer, 42 );
}
};
};

5
test/samples/import-as/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'renames named and default imports'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/import-as

5
test/samples/import-as/foo.js

@ -0,0 +1,5 @@
/* jshint esnext:true */
export var a = 'a';
export var b = 'b';
export default 'DEF';

5
test/samples/import-as/main.js

@ -0,0 +1,5 @@
import { a as b, b as a, default as def } from './foo';
assert.equal(b, 'a');
assert.equal(a, 'b');
assert.equal(def, 'DEF');

5
test/samples/import-chain/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'imports chained exports'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/import-chain

1
test/samples/import-chain/first.js

@ -0,0 +1 @@
export var value = 42;

2
test/samples/import-chain/main.js

@ -0,0 +1,2 @@
import { value } from './second';
assert.equal(value, 42);

2
test/samples/import-chain/second.js

@ -0,0 +1,2 @@
import { value } from './first';
export { value };

5
test/samples/import-default-and-named-function/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'imports default and named exports in same declaration'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default-named-function

7
test/samples/import-default-and-named-function/foo.js

@ -0,0 +1,7 @@
export default function foo() {
return 1;
}
export function callsFoo() {
return foo();
}

4
test/samples/import-default-and-named-function/main.js

@ -0,0 +1,4 @@
import foo, { callsFoo } from './foo';
assert.strictEqual(foo(), 1);
assert.strictEqual(callsFoo(), 1);

5
test/samples/import-default-as-named/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'imports a default export by a name'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default-function

3
test/samples/import-default-as-named/foo.js

@ -0,0 +1,3 @@
export default function () {
return 1;
}

6
test/samples/import-default-as-named/main.js

@ -0,0 +1,6 @@
import fn1 from './foo';
import { default as fn2 } from './foo';
assert.equal(fn1(), 1);
assert.equal(fn2(), 1);

6
test/samples/import-default-class/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'imports a default class',
babel: [ 'es6.classes' ]
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default-class

4
test/samples/import-default-class/main.js

@ -0,0 +1,4 @@
import Point from './exporter';
assert.strictEqual(new Point(1, 2).x, 1);
assert.strictEqual(new Point(1, 2).y, 2);

6
test/samples/import-default-class/point.js

@ -0,0 +1,6 @@
export default class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}

6
test/samples/import-named-class/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'imports a named class',
babel: [ 'es6.classes' ]
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-named-class

2
test/samples/import-named-class/foo.js

@ -0,0 +1,2 @@
class Foo {}
export { Foo };

3
test/samples/import-named-class/main.js

@ -0,0 +1,3 @@
import { Foo } from './foo';
assert.strictEqual(new Foo().constructor, Foo);

6
test/samples/import-nameless-class-expression/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'imports a nameless class expression',
babel: [ 'es6.classes' ]
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-class-expression

1
test/samples/import-nameless-class-expression/foo.js

@ -0,0 +1 @@
export default class {};

3
test/samples/import-nameless-class-expression/main.js

@ -0,0 +1,3 @@
import Foo from './foo';
assert.strictEqual(new Foo().constructor, Foo);

8
test/samples/import-not-at-top-level-fails/_config.js

@ -0,0 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows non-top-level imports',
error: function ( err ) {
assert.ok( false, 'TODO: pick an error message' );
}
};

3
test/samples/import-not-at-top-level-fails/index.js

@ -0,0 +1,3 @@
function foo() {
import foo from './foo';
}

10
test/samples/namespace-reassign-import-fails/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows reassignments to namespace exports',
error: function ( err ) {
assert.ok( false, 'TODO figure out correct error' );
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespace-reassign-import-fails

1
test/samples/namespace-reassign-import-fails/foo.js

@ -0,0 +1 @@
export var foo = 1;

3
test/samples/namespace-reassign-import-fails/main.js

@ -0,0 +1,3 @@
import * as exp from './foo';
exp.foo = 2;

10
test/samples/namespace-update-import-fails/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows updates to namespace exports',
error: function ( err ) {
assert.ok( false, 'TODO figure out correct error' );
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespace-update-import-fails

1
test/samples/namespace-update-import-fails/foo.js

@ -0,0 +1 @@
export var foo = 1;

3
test/samples/namespace-update-import-fails/main.js

@ -0,0 +1,3 @@
import * as exp from './foo';
exp['foo']++;

5
test/samples/namespaces/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'imports a namespace from an internal module'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespaces

3
test/samples/namespaces/foo.js

@ -0,0 +1,3 @@
export var a = 'a';
export var b = 'b';
export default 'DEF';

11
test/samples/namespaces/main.js

@ -0,0 +1,11 @@
import * as foo from './foo';
assert.equal(foo['default'], 'DEF');
assert.equal(foo.b, 'b');
assert.equal(foo.a, 'a');
var keys = [];
for (var key in foo) {
keys.push(key);
}
assert.deepEqual(keys.sort(), ['a', 'b', 'default']);

5
test/samples/re-export-default-import/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 're-exports a default import'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/re-export-default-import

3
test/samples/re-export-default-import/first.js

@ -0,0 +1,3 @@
export default function hi() {
return 'hi';
}

2
test/samples/re-export-default-import/main.js

@ -0,0 +1,2 @@
import { hi } from './second';
assert.equal(hi(), 'hi');

2
test/samples/re-export-default-import/second.js

@ -0,0 +1,2 @@
import hi from './first';
export { hi };

5
test/samples/re-export-namespace-import/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 're-exports a namespace import'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/re-export-namespace-import

2
test/samples/re-export-namespace-import/first.js

@ -0,0 +1,2 @@
export var a = 1;
export var b = 2;

4
test/samples/re-export-namespace-import/main.js

@ -0,0 +1,4 @@
import { mod } from './second';
assert.strictEqual(mod.a, 1);
assert.strictEqual(mod.b, 2);

2
test/samples/re-export-namespace-import/second.js

@ -0,0 +1,2 @@
import * as mod from './first';
export { mod };

10
test/samples/reassign-import-fails/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows assignments to imported bindings',
error: function ( err ) {
assert.ok( false, 'TODO choose error' );
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/reassign-import-fails

1
test/samples/reassign-import-fails/foo.js

@ -0,0 +1 @@
export var x = 1;

8
test/samples/reassign-import-fails/main.js

@ -0,0 +1,8 @@
import { x } from './foo';
(function() {
for(var x = 0; x < 1; x++){}
for(var x = 0; x < 1; x++){}
});
x = 10;

10
test/samples/reassign-import-not-at-top-level-fails/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows assignments to imported bindings not at the top level',
error: function ( err ) {
assert.ok( false, 'TODO choose error' );
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/reassign-import-fails

1
test/samples/reassign-import-not-at-top-level-fails/foo.js

@ -0,0 +1 @@
export var x = 1;

8
test/samples/reassign-import-not-at-top-level-fails/main.js

@ -0,0 +1,8 @@
import { x } from './foo';
export function foo () {
var x = 1;
}
export function bar () {
x = 1;
}

5
test/samples/shadowed-variables/_config.js

@ -0,0 +1,5 @@
module.exports = {
description: 'renames shadowed variables correctly'
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/named-function-expression

1
test/samples/shadowed-variables/foo.js

@ -0,0 +1 @@
export var a = 1;

9
test/samples/shadowed-variables/main.js

@ -0,0 +1,9 @@
import { a } from './foo';
var getA = function getA() {
var a = 2;
return a;
};
assert.strictEqual(a, 1);
assert.strictEqual(getA(), 2);

3
test/samples/this-is-undefined/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'this at top level is undefined'
};

1
test/samples/this-is-undefined/main.js

@ -0,0 +1 @@
assert.strictEqual( this, undefined );

10
test/samples/update-expression-of-import-fails/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'disallows updates to imported bindings',
error: function ( err ) {
assert.ok( false, 'TODO choose error' );
}
};
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/update-expression-of-import-fails

1
test/samples/update-expression-of-import-fails/foo.js

@ -0,0 +1 @@
export var a = 0;

3
test/samples/update-expression-of-import-fails/main.js

@ -0,0 +1,3 @@
import { a } from './foo';
a++;

61
test/test.js

@ -27,17 +27,45 @@ describe( 'rollup', function () {
assert.equal( typeof rollup.rollup, 'function' );;
});
sander.readdirSync( SAMPLES ).forEach( function ( dir ) {
sander.readdirSync( SAMPLES ).sort().forEach( function ( dir ) {
if ( dir[0] === '.' ) return; // .DS_Store...
var config = require( SAMPLES + '/' + dir + '/_config' );
var config;
( config.solo ? it.only : it )( config.description, function () {
try {
config = require( SAMPLES + '/' + dir + '/_config' );
} catch ( err ) {
config = { description: dir };
}
( config.solo ? it.only : it )( dir, function () {
return rollup.rollup( SAMPLES + '/' + dir + '/main.js', extend( {}, config.options ) )
.then( function ( bundle ) {
var result = bundle.generate( extend( {}, config.bundleOptions, {
format: 'cjs'
}));
var unintendedError;
if ( config.error ) {
throw new Error( 'Expected an error while rolling up' );
}
// try to generate output
try {
var result = bundle.generate( extend( {}, config.bundleOptions, {
format: 'cjs'
}));
if ( config.error ) {
unintendedError = new Error( 'Expected an error while generating output' );
}
} catch ( err ) {
if ( config.error ) {
config.error( err );
} else {
unintendedError = err;
}
}
if ( unintendedError ) throw unintendedError;
try {
var fn = new Function( 'require', 'module', 'exports', 'assert', result.code );
@ -46,17 +74,32 @@ describe( 'rollup', function () {
};
fn( require, module, module.exports, assert );
if ( config.error ) {
unintendedError = new Error( 'Expected an error while executing output' );
}
if ( config.exports ) {
config.exports( module.exports, assert );
config.exports( module.exports );
}
} catch ( err ) {
console.log( result.code );
throw err;
if ( config.error ) {
config.error( err );
} else {
unintendedError = err;
}
}
if ( unintendedError ) throw unintendedError;
if ( config.show ) {
console.log( result.code + '\n\n\n' );
}
}, function ( err ) {
if ( config.error ) {
config.error( err );
} else {
throw err;
}
});
});
});

Loading…
Cancel
Save