From 69c11a0c8192e643f4aa4c0aa79ce09cdd1ab155 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Mar 2018 17:15:26 +0100 Subject: [PATCH] Run prettier on output in build dirs (#5858) --- CHANGELOG.md | 4 +++- .../__tests__/__snapshots__/failures.test.js.snap | 2 +- .../__tests__/__snapshots__/globals.test.js.snap | 4 ++-- scripts/build.js | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e7d7572a09b..d7b5520066a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,8 +64,10 @@ ### Chore & Maintenance +* `[#5858]` Run Prettier on compiled output + ([#5858](https://github.com/facebook/jest/pull/3497)) * `[#5708]` Add fileChange hook for plugins - ([#5648](https://github.com/facebook/jest/pull/5708)) + ([#5708](https://github.com/facebook/jest/pull/5708)) * `[docs]` Add docs on using `jest.mock(...)` ([#5648](https://github.com/facebook/jest/pull/5648)) * `[docs]` Mention Jest Puppeteer Preset diff --git a/integration-tests/__tests__/__snapshots__/failures.test.js.snap b/integration-tests/__tests__/__snapshots__/failures.test.js.snap index b773dd6645e9..ccde240d4d88 100644 --- a/integration-tests/__tests__/__snapshots__/failures.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/failures.test.js.snap @@ -116,7 +116,7 @@ exports[`works with async failures 1`] = ` + \\"foo\\": \\"bar\\", } - at packages/expect/build/index.js:104:76 + at packages/expect/build/index.js:160:61 " `; diff --git a/integration-tests/__tests__/__snapshots__/globals.test.js.snap b/integration-tests/__tests__/__snapshots__/globals.test.js.snap index 280ee77d5556..b3aac3749d67 100644 --- a/integration-tests/__tests__/__snapshots__/globals.test.js.snap +++ b/integration-tests/__tests__/__snapshots__/globals.test.js.snap @@ -32,7 +32,7 @@ exports[`cannot test with no implementation 1`] = ` 4 | test('test, no implementation'); 5 | - at packages/jest-jasmine2/build/jasmine/Env.js:390:15 + at packages/jest-jasmine2/build/jasmine/Env.js:405:15 at __tests__/only-constructs.test.js:3:5 " @@ -59,7 +59,7 @@ exports[`cannot test with no implementation with expand arg 1`] = ` 4 | test('test, no implementation'); 5 | - at packages/jest-jasmine2/build/jasmine/Env.js:390:15 + at packages/jest-jasmine2/build/jasmine/Env.js:405:15 at __tests__/only-constructs.test.js:3:5 " diff --git a/scripts/build.js b/scripts/build.js index fbc9d05cb783..d687b794def5 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -28,6 +28,7 @@ const mkdirp = require('mkdirp'); const babel = require('babel-core'); const chalk = require('chalk'); const micromatch = require('micromatch'); +const prettier = require('prettier'); const stringLength = require('string-length'); const getPackages = require('./getPackages'); const browserBuild = require('./browserBuild'); @@ -46,6 +47,8 @@ const transformOptions = JSON.parse( fs.readFileSync(path.resolve(__dirname, '..', '.babelrc'), 'utf8') ); transformOptions.babelrc = false; +const prettierConfig = prettier.resolveConfig.sync(__filename); +prettierConfig.trailingComma = 'none'; const adjustToTerminalWidth = str => { const columns = process.stdout.columns || 80; @@ -161,7 +164,8 @@ function buildFile(file, silent) { } const transformed = babel.transformFileSync(file, options).code; - fs.writeFileSync(destPath, transformed); + const prettyCode = prettier.format(transformed, prettierConfig); + fs.writeFileSync(destPath, prettyCode); silent || process.stdout.write( chalk.green(' \u2022 ') +