nightwatch icon indicating copy to clipboard operation
nightwatch copied to clipboard

RangeError: Invalid string length for HTML Reporter on large job

Open ldziadkowiec opened this issue 1 year ago • 1 comments

Description of the bug/issue

When I have large nwjs job I got: "RangeError: Invalid string length" when using built in HTML Reporter.

JSON.stringify(results)
[object Object]
RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at HtmlReporter.writeReport (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\reporters\html.js:224:16)
    at Object.write (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\reporters\html.js:242:22)
    at C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:206:26
    at new Promise (<anonymous>)
    at GlobalReporter.writeReport (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:205:20)
    at C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:181:67
    at Array.map (<anonymous>)
    at GlobalReporter.writeReportToFile (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:181:42)
    at async Promise.all (index 1)
    at DefaultRunner.reportResults (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\runner\test-runners\default.js:115:13)
    at DefaultRunner.runConcurrent (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\runner\test-runners\default.js:128:9)
  ✖ RangeError
   Invalid string length
    Stack Trace :
    at JSON.stringify (<anonymous>)
    at HtmlReporter.writeReport (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\reporters\html.js:230:33)
    at Object.write (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\reporters\html.js:242:22)
    at C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:206:26
    at new Promise (<anonymous>)
    at GlobalReporter.writeReport (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:205:20)
    at C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:181:67
    at Array.map (<anonymous>)
    at GlobalReporter.writeReportToFile (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\reporter\global-reporter.js:181:42)
    at async Promise.all (index 1)
    at DefaultRunner.reportResults (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\runner\test-runners\default.js:115:13)
    at DefaultRunner.runConcurrent (C:\git\price-optimization-frontend\node_modules\nightwatch\dist\runner\test-runners\default.js:128:9)

Steps to reproduce

  1. Go to '...'
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

Sample test

Some data from the job


JSON.stringify(results)
[object Object]
{
  environments: {
    ch_win_bs: { metadata: [Object], stats: [Object], modules: [Object] }
  },
  stats: { total: 1948, passed: 1948, failed: 0, skipped: 0, time: 2445000 },
  metadata: { date: 2023-10-24T15:40:54.542Z }
}
RangeError: Invalid string length
    at JSON.stringify (<anonymous>)



### Command to run

_No response_

### Verbose Output

_No response_

### Nightwatch Configuration

_No response_

### Nightwatch.js Version

3.2.1

### Node Version

18.13.0

### Browser

chrome

### Operating System

W10

### Additional Information

_No response_

ldziadkowiec avatar Oct 24 '23 19:10 ldziadkowiec

Hi is this issue workable .. ? So far what I have inspected ..

nightwatch/lib/reporter/reporters/html --> HtmlReporter.writeReport()

const filePath = path.join(destFolder, `${this.getFileName()}.html`);

const jsonString = JSON.stringify(results);

HtmlReact.writeNightwatchHTMLReport(destFolder, fileName, jsonString);

The JSON.stirngify() function has a limit and when it exceeds that the error is thrown as shown... Maybe we can use Bson or Json stream or we can get rid of the exceeded data (which i dont think will be wise)

any suggestions.. Thanks

manthan-sharma-23 avatar Feb 25 '24 07:02 manthan-sharma-23