Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the variable name #219

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ jobs:
# but in the project folder
SPLIT_FILE: timings.json

test-pending-tests:
runs-on: ubuntu-22.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v4
- name: Needs to find the timings file 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v6
with:
project: examples/pending-timings/tests/cypress-tests
env:
SPLIT: 1
SPLIT_INDEX: 0
# the timings file is not next to the config file
# but in the project folder
SPLIT_FILE: timings.json

test-workflow-e2e:
# https://github.com/bahmutov/cypress-workflows
uses: bahmutov/cypress-workflows/.github/workflows/split.yml@v1
Expand Down Expand Up @@ -285,6 +302,7 @@ jobs:
test-index1,
test-timings,
test-timings-no-file,
test-pending-tests,
test-merge-timings,
test-find-timings-file,
preview,
Expand Down
17 changes: 17 additions & 0 deletions examples/pending-timings/tests/cypress-tests/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { defineConfig } = require('cypress')
const cypressSplit = require('../../../../src')

module.exports = defineConfig({
e2e: {
// baseUrl, etc
supportFile: false,
fixturesFolder: false,
specPattern: 'e2e/*.cy.js',
setupNodeEvents(on, config) {
console.log('cwd is', process.cwd())
cypressSplit(on, config)
// IMPORTANT: return the config object
return config
},
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it('works A', () => {})
2 changes: 2 additions & 0 deletions examples/pending-timings/tests/cypress-tests/e2e/spec-b.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this spec has all pending tests
it('works B')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it('works C', () => {})
28 changes: 28 additions & 0 deletions examples/pending-timings/tests/cypress-tests/timings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"durations": [
{
"spec": "cypress/e2e/spec-a.cy.js",
"duration": 100
},
{
"spec": "cypress/e2e/spec-b.cy.js",
"duration": 100
},
{
"spec": "cypress/e2e/spec-c.cy.js",
"duration": 1000
},
{
"spec": "e2e/spec-a.cy.js",
"duration": 115
},
{
"spec": "e2e/spec-b.cy.js",
"duration": 45
},
{
"spec": "e2e/spec-c.cy.js",
"duration": 62
}
]
}
16 changes: 16 additions & 0 deletions examples/pending-timings/timings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"durations": [
{
"spec": "cypress/e2e/spec-a.cy.js",
"duration": 100
},
{
"spec": "cypress/e2e/spec-b.cy.js",
"duration": 100
},
{
"spec": "cypress/e2e/spec-c.cy.js",
"duration": 1000
}
]
}
78 changes: 5 additions & 73 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ function cypressSplit(on, config) {
console.log('%s chunk %d of %d', label, splitIndex + 1, splitN)

debug('get chunk %o', { specs, splitN, splitIndex })
/* @type {string[]} absolute spec filenames */
// let splitSpecs

// const cwd = process.cwd()
// console.log('%s specs from the current directory %s', label, cwd)

const { splitSpecs, foundSplitFile } = splitSpecsLogic({
specs,
Expand All @@ -121,73 +116,6 @@ function cypressSplit(on, config) {
label,
})

// let foundSplitFile
// if (SPLIT_FILE) {
// debug('loading split file %s', SPLIT_FILE)
// try {
// foundSplitFile = findFile(SPLIT_FILE)
// if (!foundSplitFile) {
// throw new Error(
// `Could not find ${SPLIT_FILE} based on the current working directory ${cwd}`,
// )
// }
// const splitFile = JSON.parse(fs.readFileSync(foundSplitFile, 'utf8'))
// const previousDurations = splitFile.durations
// const averageDuration =
// previousDurations
// .map((item) => item.duration)
// .reduce((sum, duration) => (sum += duration), 0) /
// previousDurations.length
// const specsWithDurations = specs.map((specName) => {
// const relativeSpec = path.relative(cwd, specName)
// const foundInfo = previousDurations.find(
// (item) => item.spec === relativeSpec,
// )
// if (!foundInfo) {
// return {
// specName,
// duration: Math.round(averageDuration),
// }
// } else {
// return {
// specName,
// duration: Math.round(foundInfo.duration),
// }
// }
// })
// debug('splitting by duration %d ways', splitN)
// debug(specsWithDurations)
// const { chunks, sums } = splitByDuration(splitN, specsWithDurations)
// debug('split by duration')
// debug(chunks)
// debug('sums of durations for chunks')
// debug(sums)

// splitSpecs = chunks[splitIndex].map((item) => item.specName)
// console.log(
// '%s split %d specs using durations from %s file',
// label,
// specsWithDurations.length,
// SPLIT_FILE,
// )
// console.log(
// '%s approximate total duration for current chunk is %s (plus Cypress overhead)',
// label,
// humanizeDuration(Math.round(sums[splitIndex])),
// )

// printSpecsListWithDurations(chunks[splitIndex])
// } catch (err) {
// console.error('%s Could not split specs by duration', label)
// console.error(err.message)
// console.error('%s splitting as is by name', label)
// splitSpecs = getChunk(specs, splitN, splitIndex)
// printSpecsList(splitSpecs)
// }
// } else {
// splitSpecs = getChunk(specs, splitN, splitIndex)
// printSpecsList(splitSpecs)
// }
debug('split specs')
debug(splitSpecs)

Expand Down Expand Up @@ -239,12 +167,16 @@ function cypressSplit(on, config) {
if (specResult) {
const passed =
specResult.stats.passes > 0 && specResult.stats.failures === 0
const allPending = specResults.stats.tests === specResults.stats.pending
const allPending =
specResult.stats.tests === specResult.stats.pending
debug({ relativeName, passed, allPending })

if (passed || allPending) {
const duration = Math.round(
specResult.stats.duration ||
specResult.stats.wallClockDuration,
)
debug('new info %o', { relativeName, duration })
return {
spec: relativeName,
duration,
Expand Down
Loading