Skip to content

Commit

Permalink
fix: convert strings to numbers, closes #350
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 7, 2025
1 parent 9012d19 commit 61e15be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function cypressSplit(on, config, userSpecOrderFn = undefined) {
}

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

const specDurations = batchSpecs
Expand Down
20 changes: 20 additions & 0 deletions src/parse-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ const { getSpecs } = require('find-cypress-specs')
const globby = require('globby')
const { createShuffle } = require('fast-shuffle')

/**
* @typedef {Object} ParsedSplitInputs
* @property {number} SPLIT
* @property {number} SPLIT_INDEX
* @property {string|undefined} SPLIT_FILE
* @property {string|undefined} SPLIT_OUTPUT_FILE
* @property {string|undefined} ciName
*/

/**
* @returns {ParsedSplitInputs}
*/
function parseSplitInputs(env = {}, configEnv = {}) {
let SPLIT = env.SPLIT || configEnv.split || configEnv.SPLIT
let SPLIT_INDEX = env.SPLIT_INDEX || configEnv.splitIndex
Expand Down Expand Up @@ -55,6 +67,14 @@ function parseSplitInputs(env = {}, configEnv = {}) {
}
}

// convert values that should be numbers
if (typeof SPLIT === 'string') {
SPLIT = Number(SPLIT)
}
if (typeof SPLIT_INDEX === 'string') {
SPLIT_INDEX = Number(SPLIT_INDEX)
}

return { SPLIT, SPLIT_INDEX, SPLIT_FILE, SPLIT_OUTPUT_FILE, ciName }
}

Expand Down
12 changes: 11 additions & 1 deletion test/parse-inputs.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
const test = require('ava')
const path = require('path')
const { getSpecsToSplit } = require('../src/parse-inputs')
const { getSpecsToSplit, parseSplitInputs } = require('../src/parse-inputs')

function toRelative(filenames) {
const cwd = process.cwd()
return filenames.map((filename) => path.relative(cwd, filename))
}

test('parseSplitInputs converts strings to numbers', (t) => {
const inputs = parseSplitInputs({
SPLIT: '1',
SPLIT_INDEX: '2',
})

t.is(inputs.SPLIT, 1)
t.is(inputs.SPLIT_INDEX, 2)
})

test('getSpecsToSplit spec pattern', (t) => {
const specs = getSpecsToSplit({
SPEC: 'cypress/spec-a.js,cypress/integration/spec-b.js',
Expand Down

0 comments on commit 61e15be

Please sign in to comment.