Skip to content

Commit

Permalink
Merge branch 'better-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 21, 2018
2 parents e039167 + 8e7cf6b commit 2af076c
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ env:
install: npm install --ignore-scripts
before_install:
- if [[ $TRAVIS_NODE_VERSION -lt 8 ]]; then npm install --global npm@5; fi
# script: npm run ci
script: npm run ci
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.61.1
*2018-06-21*
* Do not try to deconflict "undefined" ([#2291](https://github.com/rollup/rollup/pull/2291))
* Properly track values for loop interator declarations and reassigned namespaces, add smoke test ([#2292](https://github.com/rollup/rollup/pull/2292))

## 0.61.0
*2018-06-20*
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
},
"scripts": {
"pretest": "npm run build",
"test": "npm run test:only && npm run test:typescript",
"test": "npm run test:only && npm run test:typescript && npm run test:leak",
"test:only": "mocha",
"test:leak": "node --expose-gc test/leak/index.js",
"test:quick": "mocha -b",
"test:leak": "npm i --silent --no-save weak@1 && node --expose-gc test/leak/index.js",
"pretest:typescript": "shx rm -rf test/typescript/dist && shx cp -r dist test/typescript/",
"test:typescript": "tsc -p test/typescript",
"pretest-coverage": "npm run build",
"test-coverage": "shx rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js",
"posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist",
"ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov",
"ci": "npm run test && npm run build:bootstrap && npm run test:only",
"prebuild": "shx rm -rf dist",
"build": "git rev-parse HEAD > .commithash && rollup -c && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x bin/rollup",
"build:bootstrap": "bin/rollup -c && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x bin/rollup",
"watch": "rollup -cw",
"prepublishOnly": "npm run lint && npm run test && npm run test:leak",
"prepublishOnly": "npm run lint && npm run test",
"prepare": "npm run build",
"lint": "tslint --project . --fix && eslint --fix src browser bin test/test.js test/*/index.js test/utils test/**/_config.js",
"precommit": "lint-staged",
Expand Down Expand Up @@ -87,7 +88,7 @@
"pretty-ms": "^3.1.0",
"remap-istanbul": "^0.11.1",
"require-relative": "^0.8.7",
"rollup": "^0.59.1",
"rollup": "^0.60.7",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-json": "^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/ast/nodes/ForInStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class ForInStatement extends StatementBase {
include() {
this.included = true;
this.left.includeWithAllDeclaredVariables();
this.left.reassignPath(EMPTY_PATH);
this.right.include();
this.body.include();
}
Expand Down
1 change: 1 addition & 0 deletions src/ast/nodes/ForOfStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class ForOfStatement extends StatementBase {
include() {
this.included = true;
this.left.includeWithAllDeclaredVariables();
this.left.reassignPath(EMPTY_PATH);
this.right.include();
this.body.include();
}
Expand Down
11 changes: 11 additions & 0 deletions src/ast/variables/NamespaceVariable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AstContext } from '../../Module';
import { RenderOptions } from '../../utils/renderHelpers';
import Identifier from '../nodes/Identifier';
import { UNKNOWN_PATH } from '../values';
import Variable from './Variable';

export default class NamespaceVariable extends Variable {
Expand Down Expand Up @@ -45,6 +46,16 @@ export default class NamespaceVariable extends Variable {
return this.referencedEarly;
}

// This is only called if "UNKNOWN_PATH" is reassigned as in all other situations, either the
// build fails due to an illegal namespace reassignment or MemberExpression already forwards
// the reassignment to the right variable. This means we lost track of this variable and thus
// need to reassign all exports.
reassignPath() {
for (const key in this.originals) {
this.originals[key].reassignPath(UNKNOWN_PATH);
}
}

renderBlock(options: RenderOptions) {
const _ = options.compact ? '' : ' ';
const n = options.compact ? '' : '\n';
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/aaa/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'treat for-in variable as unknown'
};
13 changes: 13 additions & 0 deletions test/function/samples/aaa/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
for (const name in {present: true}) {
if (name !== 'present') {
throw new Error('Always false for-in check was inlined');
}
assert.equal(name, 'present');
}

for (const name of ['present']) {
if (name !== 'present') {
throw new Error('Always false for-of check was inlined');
}
assert.equal(name, 'present');
}
3 changes: 3 additions & 0 deletions test/function/samples/reassign-namespace/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'members of namespaces are reassigned when the namespace is passed to a function'
};
10 changes: 10 additions & 0 deletions test/function/samples/reassign-namespace/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const flags = {};

function test() {
if (!flags.x) {
throw new Error('Flag "x" not set');
}
assert.ok(flags.x);
}

export { flags, test };
9 changes: 9 additions & 0 deletions test/function/samples/reassign-namespace/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as foo from './foo.js';

function reassignFlagX(obj) {
obj.flags.x = true;
}

reassignFlagX(foo);

foo.test();
74 changes: 28 additions & 46 deletions test/leak/index.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,38 @@
const path = require('path');
const rollup = require('../..');
const weak = require('weak');

function test() {
const weak = require('weak');
var shouldCollect = false;
var isCollected = false;

var shouldCollect = false;
var isCollected = false;

function onCollect() {
isCollected = true;
}

var cache;
function run() {
return rollup
.rollup({
input: path.resolve(__dirname, 'main.js'),
cache
})
.then(bundle => {
weak(bundle, onCollect);
cache = bundle;
global.gc();
if (shouldCollect && !isCollected) {
throw new Error('Memory leak detected');
}
shouldCollect = true;
});
}
function onCollect() {
isCollected = true;
}

run()
.then(run)
.then(() => {
console.log('Success');
var cache;
function run() {
return rollup
.rollup({
input: path.resolve(__dirname, 'main.js'),
cache
})
.catch(err => {
console.error(err.message);
process.exit(1);
.then(bundle => {
weak(bundle, onCollect);
cache = bundle;
global.gc();
if (shouldCollect && !isCollected) {
throw new Error('Memory leak detected');
}
shouldCollect = true;
});
}

try {
require.resolve('weak');
test();
} catch (err) {
console.error(err);
console.log('installing weak');
require('child_process').exec('npm i --no-save --silent weak@1.0.1', (err, stdout, stderr) => {
if (err) {
console.log('failed to install weak');
} else {
test();
}
run()
.then(run)
.then(() => {
console.log('Success: No memory leak detected');
})
.catch(err => {
console.error(err.message);
process.exit(1);
});
}

0 comments on commit 2af076c

Please sign in to comment.