Skip to content

Commit

Permalink
Improved runtime of tests through parallel execution. Unfortunately w…
Browse files Browse the repository at this point in the history
…e still have to wait for Jest to support async describe. jestjs/jest#5673
  • Loading branch information
swernerx committed Apr 27, 2018
1 parent e3d3790 commit af7903d
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 43 deletions.
8 changes: 5 additions & 3 deletions __tests__/binary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Binary", () => {
const options = buildPreset(null, {
Expand All @@ -8,7 +8,9 @@ describe("Binary", () => {
env: "production"
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
return getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/browserslist-prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Browserslist Production", () => {
const options = buildPreset(null, {
Expand All @@ -8,7 +8,9 @@ describe("Browserslist Production", () => {
env: "production"
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/browserslist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Browserslist", () => {
const options = buildPreset(null, {
Expand All @@ -8,7 +8,9 @@ describe("Browserslist", () => {
env: "development"
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/compressed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Compressed", () => {
const options = buildPreset(null, {
Expand All @@ -8,7 +8,9 @@ describe("Compressed", () => {
compression: true
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
12 changes: 8 additions & 4 deletions __tests__/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { transformFile } from "babel-core"
import { readdirSync } from "fs"
import { readdir } from "fs"

const FIXTURE_ROOT = "./__tests__/__fixtures__/"

Expand All @@ -23,13 +23,17 @@ export function check(fixture, options) {
})
}

export const fixtures = readdirSync(FIXTURE_ROOT)

export function getTitle(fileName) {
return fileName
.replace(/\.js$/, "")
.replace(/_/, ": ")
.replace(/-/, " ")
}

export const titles = fixtures.map(getTitle)
export function getFixtures() {
return new Promise((resolve, reject) => {
readdir(FIXTURE_ROOT, (error, fixtures) => {
resolve([fixtures, fixtures.map(getTitle)])
})
})
}
8 changes: 5 additions & 3 deletions __tests__/es2015.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("ES2015", () => {
const options = buildPreset(null, {
Expand All @@ -8,7 +8,9 @@ describe("ES2015", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/ie11.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("IE11", () => {
const options = buildPreset(null, {
Expand All @@ -8,7 +8,9 @@ describe("IE11", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/modern.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Modern", () => {
const options = buildPreset(null, {
Expand All @@ -8,7 +8,9 @@ describe("Modern", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/node10.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Node v10", () => {
const options = buildPreset(null, {
Expand All @@ -9,7 +9,9 @@ describe("Node v10", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/node6.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Node v6", () => {
const options = buildPreset(null, {
Expand All @@ -9,7 +9,9 @@ describe("Node v6", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/node8.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Node v8", () => {
const options = buildPreset(null, {
Expand All @@ -9,7 +9,9 @@ describe("Node v8", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/nonloose.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Non Loose", () => {
const options = buildPreset(null, {
Expand All @@ -10,7 +10,9 @@ describe("Non Loose", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/production.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Production", () => {
const options = buildPreset(null, {
Expand All @@ -9,7 +9,9 @@ describe("Production", () => {
env: "production"
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})
8 changes: 5 additions & 3 deletions __tests__/webpack.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import buildPreset from "../src"
import { fixtures, titles, check } from "./core"
import { getFixtures, check } from "./core"

describe("Webpack", () => {
const options = buildPreset(null, {
Expand All @@ -9,7 +9,9 @@ describe("Webpack", () => {
sourceMaps: false
})

fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
getFixtures().then((fixtures, titles) => {
fixtures.forEach((fileName, index) => {
test(titles[index], () => check(fileName, options))
})
})
})

0 comments on commit af7903d

Please sign in to comment.