Skip to content

Commit

Permalink
rename to squeeze out a bit more balanced perf (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann committed Aug 13, 2018
1 parent fc7eb53 commit 47c0d67
Show file tree
Hide file tree
Showing 64 changed files with 77 additions and 21 deletions.
14 changes: 7 additions & 7 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ jobs:
- restore_cache:
key: cypress-{{ .Branch }}-{{ .Revision }}
- run:
command: npm run test-e2e -- --index 0
command: npm run test-e2e -- --chunk 1
working_directory: packages/server
- store_test_results:
path: /tmp/cypress
Expand All @@ -254,7 +254,7 @@ jobs:
- restore_cache:
key: cypress-{{ .Branch }}-{{ .Revision }}
- run:
command: npm run test-e2e -- --index 1
command: npm run test-e2e -- --chunk 2
working_directory: packages/server
- store_test_results:
path: /tmp/cypress
Expand All @@ -265,7 +265,7 @@ jobs:
- restore_cache:
key: cypress-{{ .Branch }}-{{ .Revision }}
- run:
command: npm run test-e2e -- --index 2
command: npm run test-e2e -- --chunk 3
working_directory: packages/server
- store_test_results:
path: /tmp/cypress
Expand All @@ -276,7 +276,7 @@ jobs:
- restore_cache:
key: cypress-{{ .Branch }}-{{ .Revision }}
- run:
command: npm run test-e2e -- --index 3
command: npm run test-e2e -- --chunk 4
working_directory: packages/server
- store_test_results:
path: /tmp/cypress
Expand All @@ -287,7 +287,7 @@ jobs:
- restore_cache:
key: cypress-{{ .Branch }}-{{ .Revision }}
- run:
command: npm run test-e2e -- --index 4
command: npm run test-e2e -- --chunk 5
working_directory: packages/server
- store_test_results:
path: /tmp/cypress
Expand All @@ -298,7 +298,7 @@ jobs:
- restore_cache:
key: cypress-{{ .Branch }}-{{ .Revision }}
- run:
command: npm run test-e2e -- --index 5
command: npm run test-e2e -- --chunk 6
working_directory: packages/server
- store_test_results:
path: /tmp/cypress
Expand All @@ -309,7 +309,7 @@ jobs:
- restore_cache:
key: cypress-{{ .Branch }}-{{ .Revision }}
- run:
command: npm run test-e2e -- --index 6
command: npm run test-e2e -- --chunk 7
working_directory: packages/server
- store_test_results:
path: /tmp/cypress
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/server/test/scripts/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const started = new Date()
let numFailed = 0

function isLoadBalanced (options) {
return _.isNumber(options.index)
return _.isNumber(options.chunk)
}

function spawn (cmd, args, opts) {
Expand All @@ -43,7 +43,7 @@ glob('test/e2e/**/*')

if (isLoadBalanced(options)) {
return _.filter(specs, (spec) => {
return path.basename(spec).startsWith(options.index)
return path.basename(spec).startsWith(options.chunk)
})
}

Expand Down
80 changes: 68 additions & 12 deletions packages/server/test/scripts/rename.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,80 @@
/* eslint-disable no-console */

require('@packages/coffee/register')

const _ = require('lodash')
const path = require('path')
const Promise = require('bluebird')
const minimist = require('minimist')
const fs = require('../../lib/util/fs')
const glob = require('../../lib/util/glob')

glob('test/e2e/**/*')
.map((spec) => {
spec += '.js'
const options = minimist(process.argv.slice(2))

const specName = path.basename(spec)
const { size, reset, snapshots } = options

const pathToSnapshot = path.resolve(
__dirname, '..', '..', '__snapshots__', specName.slice(2)
)
const removeChunkPrefixes = () => {
const forwardSlashNumUnderscoreRe = /(\/\d_)/

const renameFiles = (pattern) => {
return glob(pattern)
.map((spec) => {
return fs.renameAsync(spec, spec.replace(forwardSlashNumUnderscoreRe, '/'))
})
}

const pathToRenamedSnapshot = path.join(
path.dirname(pathToSnapshot),
specName
return Promise.join(
renameFiles('test/e2e/**/*'),
renameFiles('__snapshots__/**/*')
)
}

const renameSnapshotsToMatchSpecs = () => {
glob('test/e2e/**/*')
.map((spec) => {
spec += '.js'

const specName = path.basename(spec)

const pathToSnapshot = path.resolve(
__dirname, '..', '..', '__snapshots__', specName.slice(2)
)

const pathToRenamedSnapshot = path.join(
path.dirname(pathToSnapshot),
specName
)

return fs.renameAsync(pathToSnapshot, pathToRenamedSnapshot)
})
.catchReturn({ code: 'ENOENT' }, null)
}

if (reset) {
return removeChunkPrefixes()
}

if (snapshots) {
return renameSnapshotsToMatchSpecs()
}

glob('test/e2e/**/*')
.then((specs) => {
if (!size) {
console.error('must include --size for calculating chunk size')
}

return _.chunk(specs, size)
})
.map((chunks, index) => {
index += 1

return Promise
.map(chunks, (spec) => {
const folder = path.dirname(spec)
const specName = path.basename(spec)
const renamedSpec = `${index}_${specName}`

return fs.renameAsync(pathToSnapshot, pathToRenamedSnapshot)
return fs.renameAsync(spec, path.join(folder, renamedSpec))
})
})
.catchReturn({ code: 'ENOENT' }, null)

0 comments on commit 47c0d67

Please sign in to comment.