Skip to content

Commit

Permalink
tests: add test using @babel/parser instead of babylon
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Sep 19, 2018
1 parent 7b4bcee commit ac0ae58
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"devDependencies": {
"@babel/core": "7.1.0",
"@babel/parser": "7.1.0",
"@babel/preset-env": "7.1.0",
"del": "3.0.0",
"eslint": "5.5.0",
Expand Down
43 changes: 43 additions & 0 deletions test/it/it.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const path = require('path');
const rollup = require('rollup');
const tmp = require('tmp');
const Q = require('q');
const babelParser = require('@babel/parser');
const prettier = require('../../dist/index.js');

describe('rollup-plugin-prettier', () => {
Expand Down Expand Up @@ -86,6 +87,48 @@ describe('rollup-plugin-prettier', () => {
});
});

it('should run prettier with @babel/parser instead of babylon', (done) => {
const output = path.join(tmpDir.name, 'bundle.js');
const config = {
input: path.join(__dirname, 'fixtures', 'bundle.js'),
output: {
file: output,
format: 'es',
},

plugins: [
prettier({
parser(text) {
return babelParser.parse(text, {
sourceType: 'module',
});
},
}),
],
};

rollup.rollup(config)
.then((bundle) => bundle.write(config.output))
.then(() => {
fs.readFile(output, 'utf8', (err, data) => {
if (err) {
done.fail(err);
}

const content = data.toString();

expect(content).toBeDefined();
expect(content).toContain(
'function sum(array) {\n' +
' return array.reduce((acc, x) => acc + x, 0);\n' +
'}'
);

done();
});
});
});

it('should run prettier on final bundle with sourcemap set in output option', (done) => {
const output = path.join(tmpDir.name, 'bundle.js');
const config = {
Expand Down

0 comments on commit ac0ae58

Please sign in to comment.