Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically generate missing expected.js fixtures #4735

Merged
merged 1 commit into from Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -145,9 +145,9 @@ If you need to check for an error that is thrown you can add to the `options.jso
}
```

##### `babylon`
##### Bootstrapping expected output

For `babylon` specifically, you can easily generate an `expected.json` automatically by just providing the `actual.js` and running `make test-only` as you usually would.
For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js`/`expected.json` automatically by just providing `actual.js` and running the tests as you usually would.

```
// Example
Expand Down
14 changes: 7 additions & 7 deletions packages/babel-helper-transform-fixture-test-runner/src/index.js
Expand Up @@ -8,6 +8,8 @@ import assert from "assert";
import chai from "chai";
import _ from "lodash";
import "babel-polyfill";
import fs from "fs";
import path from "path";

let babelHelpers = eval(buildExternalHelpers(null, "var"));

Expand Down Expand Up @@ -63,14 +65,12 @@ function run(task) {
let actualCode = actual.code;
let expectCode = expect.code;
if (!execCode || actualCode) {
result = babel.transform(actualCode, getOpts(actual));
actualCode = result.code.trim();

try {
result = babel.transform(actualCode, getOpts(actual));
if (!expect.code && result.code && !opts.throws && fs.statSync(path.dirname(expect.loc)).isDirectory() && !process.env.CI) {
fs.writeFileSync(expect.loc, result.code);
} else {
actualCode = result.code.trim();
chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
} catch (err) {
//require("fs").writeFileSync(expect.loc, actualCode);
throw err;
}
}

Expand Down