CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Custom chunking function showing unexpected errors even when using copy/paste code from the docs.

Open Jtech42 opened this issue 8 years ago • 1 comments

What are you trying to achieve?

Using a custom chunking algorithm per the example code from the guide - https://codecept.io/advanced/#parallel-execution

What do you get instead?

The guides json has issues? Json errors if you try to use the demo code in the guide, after removing the comments, then I'm adding ""s to make sure the json can be parsed and seeing SyntaxError: Unexpected token (, at the start of the function. THEN TypeError: config.chunks.call is not a function, THEN Error: chunks is neither a finite number or a valid function. Been trying to get it to work, not sure what else to try.

undefined:1
function(files){return[[ files[0] ],[files[ files.length-1 ]],]}
        ^

SyntaxError: Unexpected token (
    at createChunks (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/codeceptjs/lib/command/run-multiple/chunk.js:64:33)
    at runs.forEach (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/codeceptjs/lib/command/run-multiple/collection.js:78:7)
    at Array.forEach (<anonymous>)
    at Collection.prepareChunks (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/codeceptjs/lib/command/run-multiple/collection.js:69:15)
    at Object.createRuns (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/codeceptjs/lib/command/run-multiple/collection.js:11:6)
    at Command.module.exports (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/codeceptjs/lib/command/run-multiple.js:67:14)
    at Command.listener (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/commander/index.js:315:8)
    at Command.emit (events.js:159:13)
    at Command.parseArgs (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/commander/index.js:651:12)
    at Command.parse (/usr/local/lib/node_modules/codeceptjs-protractor/node_modules/commander/index.js:474:21)```

Codecept.json from the docs:

  "parallel": {
    // Splits tests into chunks by passing an anonymous function,
    // only execute first and last found test file
    "chunks": (files) => {
      return [
        [ files[0] ], // chunk 1
        [ files[files.length-1] ], // chunk 2
      ]
    },
    // run all tests in chrome and firefox
    "browsers": ["chrome", "firefox"]
  }
}

Below is my fix to that json in the guide. This fix doesn't actually pass the array it just gets past the obvious json errors that will occur if you use the guide.

"multiple": {
  "parallel": {
    "chunks": "function(files){return[[ files[0] ],[files[ files.length-1 ]],]}",
    "browsers": ["chrome"]
  }
}

Jtech42 avatar Dec 04 '18 23:12 Jtech42

The reason is in another place in the docs https://codecept.io/configuration/ it discusses using a codecept.conf.js file. I was able to fix it (sort of) by converting the json to a js file.

Jtech42 avatar Dec 05 '18 21:12 Jtech42