Skip to content

Commit 61e15be

Browse files
committed
fix: convert strings to numbers, closes #350
1 parent 9012d19 commit 61e15be

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function cypressSplit(on, config, userSpecOrderFn = undefined) {
194194
}
195195

196196
on('after:run', () => {
197-
if (SPLIT_FILE) {
197+
if (SPLIT_FILE && SPLIT_OUTPUT_FILE) {
198198
console.log('%s here are passing spec timings', label)
199199

200200
const specDurations = batchSpecs

src/parse-inputs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ const { getSpecs } = require('find-cypress-specs')
55
const globby = require('globby')
66
const { createShuffle } = require('fast-shuffle')
77

8+
/**
9+
* @typedef {Object} ParsedSplitInputs
10+
* @property {number} SPLIT
11+
* @property {number} SPLIT_INDEX
12+
* @property {string|undefined} SPLIT_FILE
13+
* @property {string|undefined} SPLIT_OUTPUT_FILE
14+
* @property {string|undefined} ciName
15+
*/
16+
17+
/**
18+
* @returns {ParsedSplitInputs}
19+
*/
820
function parseSplitInputs(env = {}, configEnv = {}) {
921
let SPLIT = env.SPLIT || configEnv.split || configEnv.SPLIT
1022
let SPLIT_INDEX = env.SPLIT_INDEX || configEnv.splitIndex
@@ -55,6 +67,14 @@ function parseSplitInputs(env = {}, configEnv = {}) {
5567
}
5668
}
5769

70+
// convert values that should be numbers
71+
if (typeof SPLIT === 'string') {
72+
SPLIT = Number(SPLIT)
73+
}
74+
if (typeof SPLIT_INDEX === 'string') {
75+
SPLIT_INDEX = Number(SPLIT_INDEX)
76+
}
77+
5878
return { SPLIT, SPLIT_INDEX, SPLIT_FILE, SPLIT_OUTPUT_FILE, ciName }
5979
}
6080

test/parse-inputs.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
const test = require('ava')
22
const path = require('path')
3-
const { getSpecsToSplit } = require('../src/parse-inputs')
3+
const { getSpecsToSplit, parseSplitInputs } = require('../src/parse-inputs')
44

55
function toRelative(filenames) {
66
const cwd = process.cwd()
77
return filenames.map((filename) => path.relative(cwd, filename))
88
}
99

10+
test('parseSplitInputs converts strings to numbers', (t) => {
11+
const inputs = parseSplitInputs({
12+
SPLIT: '1',
13+
SPLIT_INDEX: '2',
14+
})
15+
16+
t.is(inputs.SPLIT, 1)
17+
t.is(inputs.SPLIT_INDEX, 2)
18+
})
19+
1020
test('getSpecsToSplit spec pattern', (t) => {
1121
const specs = getSpecsToSplit({
1222
SPEC: 'cypress/spec-a.js,cypress/integration/spec-b.js',

0 commit comments

Comments
 (0)