Skip to content

Commit

Permalink
fix($refactor): provide consistent argument order to flush functions
Browse files Browse the repository at this point in the history
  • Loading branch information
faceyspacey committed Apr 27, 2017
1 parent 6d3b5ed commit 76f6b19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions __tests__/flushChunks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ describe('flushChunks() called as pure function', () => {
/** BABEL VS. WEBPACK FLUSHING */

test('flushBabel()', () => {
const files = flushBabel(stats, babelFilePaths, rootDir) /*? */
const files = flushBabel(babelFilePaths, stats, rootDir) /*? */
const allFiles = stats.chunks[0].files.concat(stats.chunks[1].files)
expect(files).toEqual(allFiles)
})

test('flushWebpack()', () => {
const files = flushWebpack(stats, webpackModuleIds) /*? */
const files = flushWebpack(webpackModuleIds, stats) /*? */
const allFiles = stats.chunks[0].files.concat(stats.chunks[1].files)
expect(files).toEqual(allFiles)
})

test('flushBabel() throws with no rootDir argument', () => {
const flush = () => flushBabel(stats, babelFilePaths) /*? */
const flush = () => flushBabel(babelFilePaths, stats) /*? */
expect(flush).toThrow()
})

Expand All @@ -94,8 +94,8 @@ test('createFilesByModuleId()', () => {

expect(Object.keys(filesByPath)).toEqual(webpackModuleIds)

expect(filesByPath['qwer']).toEqual(['0.js', '0.no_css.js', '0.css'])
expect(filesByPath['zxcv']).toEqual([]) // test against arrays of undefined
expect(filesByPath.qwer).toEqual(['0.js', '0.no_css.js', '0.css'])
expect(filesByPath.zxcv).toEqual([]) // test against arrays of undefined

expect(filesByPath).toMatchSnapshot()
})
Expand Down
8 changes: 4 additions & 4 deletions src/flushChunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const flushChunks = (
const beforeEntries = opts.before || defaults.before

const files = !isWebpack
? flushBabel(stats, pathsOrIds, opts.rootDir)
: flushWebpack(stats, pathsOrIds)
? flushBabel(pathsOrIds, stats, opts.rootDir)
: flushWebpack(pathsOrIds, stats)

const afterEntries = opts.after || defaults.after

Expand All @@ -75,7 +75,7 @@ const flushChunks = (

/** BABEL VS. WEBPACK FLUSHING */

const flushBabel = (stats: Stats, paths: Files, rootDir: ?string): Files => {
const flushBabel = (paths: Files, stats: Stats, rootDir: ?string): Files => {
if (!rootDir) {
throw new Error(
`No \`rootDir\` was provided as an option to \`flushChunks\`.
Expand All @@ -94,7 +94,7 @@ const flushBabel = (stats: Stats, paths: Files, rootDir: ?string): Files => {
return concatFilesAtKeys(filesByPath, paths.map(p => normalizePath(p, dir)))
}

const flushWebpack = (stats: Stats, ids: Files): Files => {
const flushWebpack = (ids: Files, stats: Stats): Files => {
filesByModuleId = filesByModuleId && !IS_TEST
? filesByModuleId // cached
: createFilesByModuleId(stats)
Expand Down

0 comments on commit 76f6b19

Please sign in to comment.