ui5-test-runner 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui5-test-runner",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Standalone test runner for UI5",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -52,7 +52,7 @@
52
52
  "reserve": "^1.15.2"
53
53
  },
54
54
  "devDependencies": {
55
- "jest": "^29.4.3",
55
+ "jest": "^29.5.0",
56
56
  "nock": "^13.3.0",
57
57
  "nyc": "^15.1.0",
58
58
  "standard": "^17.0.0"
@@ -95,4 +95,4 @@
95
95
  }
96
96
  }
97
97
  }
98
- }
98
+ }
@@ -3,6 +3,7 @@
3
3
  const { join } = require('path')
4
4
  const { readFile, writeFile } = require('fs').promises
5
5
  const [,, reportDir] = process.argv
6
+ const { resolveDependencyPath } = require('../npm.js')
6
7
 
7
8
  const defaultDir = join(__dirname, 'report')
8
9
 
@@ -11,7 +12,7 @@ async function readDefault (name) {
11
12
  }
12
13
 
13
14
  async function readDependency (name) {
14
- return (await readFile(join(__dirname, '../../node_modules', name, 'dist', `${name}.js`))).toString()
15
+ return (await readFile(resolveDependencyPath(name))).toString()
15
16
  }
16
17
 
17
18
  function minifyJs (src) {
package/src/endpoints.js CHANGED
@@ -10,6 +10,10 @@ const { addTestPages } = require('./add-test-pages')
10
10
  const { getJobProgress } = require('./get-job-progress')
11
11
  const { readFile } = require('fs/promises')
12
12
  const { TextEncoder } = require('util')
13
+ const { resolveDependencyPath } = require('./npm.js')
14
+
15
+ const punyexprBinPath = resolveDependencyPath('punyexpr')
16
+ const punybindBinPath = resolveDependencyPath('punybind')
13
17
 
14
18
  module.exports = job => {
15
19
  async function endpointImpl (api, implementation, request) {
@@ -131,11 +135,11 @@ module.exports = job => {
131
135
  }, {
132
136
  // punybind
133
137
  match: '^/_/punybind.js',
134
- file: join(__dirname, '../node_modules/punybind/dist/punybind.js')
138
+ file: punybindBinPath
135
139
  }, {
136
140
  // punyexpr
137
141
  match: '^/_/punyexpr.js',
138
- file: join(__dirname, '../node_modules/punyexpr/dist/punyexpr.js')
142
+ file: punyexprBinPath
139
143
  }, {
140
144
  // Endpoint to follow progress
141
145
  match: '^/_/progress(?:\\?page=([^&]*)(?:&test=([^&]*))?)?',
package/src/job.js CHANGED
@@ -258,7 +258,10 @@ function finalize (job) {
258
258
  function fromCmdLine (cwd, args) {
259
259
  let job = parse(cwd, args)
260
260
 
261
- const defaultPath = join(job.cwd, 'ui5-test-runner.json')
261
+ let defaultPath = join(job.cwd, 'ui5-test-runner.json')
262
+ if (!isAbsolute(defaultPath)) {
263
+ defaultPath = join(job.initialCwd, defaultPath)
264
+ }
262
265
  let hasDefaultSettings = false
263
266
  try {
264
267
  checkAccess({ path: defaultPath, file: true })
package/src/npm.js CHANGED
@@ -32,6 +32,11 @@ let localRoot
32
32
  let globalRoot
33
33
 
34
34
  module.exports = {
35
+ resolveDependencyPath (name) {
36
+ require(name)
37
+ return Object.keys(require.cache).filter(path => path.endsWith(`${name}.js`))[0]
38
+ },
39
+
35
40
  async resolvePackage (job, name) {
36
41
  if (!localRoot) {
37
42
  [localRoot, globalRoot] = await Promise.all([
package/src/output.js CHANGED
@@ -345,27 +345,33 @@ function build (job) {
345
345
  log(job, p`└──────────${pad.x('─')}┘`)
346
346
  }),
347
347
 
348
- monitor (childProcess) {
348
+ monitor (childProcess, live = true) {
349
+ const defaults = {
350
+ stdout: { buffer: [], method: log },
351
+ stderr: { buffer: [], method: err }
352
+ };
349
353
  ['stdout', 'stderr'].forEach(channel => {
350
- const defaults = {
351
- stdout: { buffer: [], method: log },
352
- stderr: { buffer: [], method: err }
353
- }
354
354
  childProcess[channel].on('data', chunk => {
355
355
  const { buffer, method } = defaults[channel]
356
356
  const text = chunk.toString()
357
- if (!text.includes('\n')) {
357
+ if (live) {
358
+ if (!text.includes('\n')) {
359
+ buffer.push(text)
360
+ return
361
+ }
362
+ const cached = buffer.join('')
363
+ const last = text.split('\n').slice(-1)
364
+ buffer.length = 0
365
+ if (last) {
366
+ buffer.push(last)
367
+ }
368
+ wrap(() => method(job, cached + text.split('\n').slice(0, -1).join('\n')))()
369
+ } else {
358
370
  buffer.push(text)
359
- return
360
371
  }
361
- const cached = buffer.join('')
362
- const last = text.split('\n').slice(-1)
363
- buffer.length = 0
364
- if (last) {
365
- buffer.push(last)
366
- }
367
- wrap(() => method(job, cached + text.split('\n').slice(0, -1).join('\n')))()
368
372
  })
373
+ })
374
+ if (live) {
369
375
  childProcess.on('close', () => {
370
376
  ['stdout', 'stderr'].forEach(channel => {
371
377
  const { buffer, method } = defaults[channel]
@@ -374,7 +380,11 @@ function build (job) {
374
380
  }
375
381
  })
376
382
  })
377
- })
383
+ }
384
+ return {
385
+ stdout: defaults.stdout.buffer,
386
+ stderr: defaults.stderr.buffer
387
+ }
378
388
  },
379
389
 
380
390
  nyc: wrap((...args) => {
@@ -499,6 +509,19 @@ function build (job) {
499
509
  }
500
510
  }),
501
511
 
512
+ reportGeneratorFailed: wrap((generator, exitCode, buffers) => {
513
+ const p = p80()
514
+ log(job, p`┌──────────${pad.x('─')}┐`)
515
+ log(job, p`│ REPORT GENERATOR FAILED ${pad.x(' ')} │`)
516
+ log(job, p`├───────────┬─${pad.x('─')}──┤`)
517
+ log(job, p`│ generator │ ${pad.lt(generator)} │`)
518
+ log(job, p`├───────────┼─${pad.x('─')}──┤`)
519
+ log(job, p`│ exit code │ ${pad.lt(exitCode.toString())} │`)
520
+ log(job, p`├───────────┴─${pad.x('─')}──┤`)
521
+ log(job, p`│ ${pad.w(buffers.stderr.join(''))} │`)
522
+ log(job, p`└──────────${pad.x('─')}┘`)
523
+ }),
524
+
502
525
  stop () {
503
526
  if (this.reportIntervalId) {
504
527
  clearInterval(this.reportIntervalId)
package/src/report.js CHANGED
@@ -8,7 +8,12 @@ const { fork } = require('child_process')
8
8
  const { getOutput } = require('./output')
9
9
 
10
10
  async function serialize (job, filename, json) {
11
- await writeFile(join(job.reportDir, `${filename}.js`), `module.exports = ${JSON.stringify(json, undefined, 2)}`)
11
+ await writeFile(join(job.reportDir, `${filename}.js`), `module.exports = ${JSON.stringify(json, (key, value) => {
12
+ if (value && value instanceof RegExp) {
13
+ return value.toString()
14
+ }
15
+ return value
16
+ }, 2)}`)
12
17
  }
13
18
 
14
19
  async function save (job) {
@@ -28,10 +33,14 @@ module.exports = {
28
33
  await save(job)
29
34
  const promises = job.reportGenerator.map(generator => {
30
35
  const { promise, resolve } = allocPromise()
31
- const childProcess = fork(generator, [job.reportDir], {
32
- stdio: [0, 0, 0, 'ipc']
36
+ const childProcess = fork(generator, [job.reportDir], { stdio: 'pipe' })
37
+ const buffers = output.monitor(childProcess, false)
38
+ childProcess.on('close', exitCode => {
39
+ if (exitCode !== 0) {
40
+ output.reportGeneratorFailed(generator, exitCode, buffers)
41
+ }
42
+ resolve()
33
43
  })
34
- childProcess.on('close', resolve)
35
44
  return promise
36
45
  })
37
46
  promises.push(generateCoverageReport(job))
package/src/reserve.js CHANGED
@@ -10,6 +10,7 @@ module.exports = job => check({
10
10
  port: job.port,
11
11
  mappings: [
12
12
  cors,
13
+ ...job.mappings ?? [],
13
14
  ...job.serveOnly ? [] : endpoints(job),
14
15
  ...ui5(job),
15
16
  ...job.serveOnly ? [] : coverage(job), {
@@ -19,7 +20,6 @@ module.exports = job => check({
19
20
  strict: true,
20
21
  'ignore-if-not-found': true
21
22
  },
22
- ...job.mappings ?? [],
23
23
  ...unhandled(job)
24
24
  ]
25
25
  })
@@ -120,6 +120,35 @@ describe('simulate', () => {
120
120
  }
121
121
  }
122
122
 
123
+ describe('mappings', () => {
124
+ beforeAll(async () => {
125
+ await setup('mappings', {
126
+ mappings: [
127
+ '/overridden/resources/(.*)=file(./LICENSE)'
128
+ ]
129
+ })
130
+ })
131
+
132
+ const urls = [
133
+ '/webapp/resources/sap-ui-core.js',
134
+ '/resources/sap-ui-core.js',
135
+ '/custom/resources/sap-ui-core.js'
136
+ ]
137
+ urls.forEach(url => {
138
+ it(`fetches UI5 resources whichever path is used (${url})`, async () => {
139
+ const response = await get(url, 'test.html')
140
+ expect(response.statusCode).toStrictEqual(200)
141
+ expect(response.toString().includes('/sap-ui-core.js */')).toStrictEqual(true)
142
+ })
143
+ })
144
+
145
+ it('enables overridding through mappings', async () => {
146
+ const response = await get('/overridden/resources/sap-ui-core.js', 'test.html')
147
+ expect(response.statusCode).toStrictEqual(200)
148
+ expect(response.toString().startsWith('MIT License')).toStrictEqual(true)
149
+ })
150
+ })
151
+
123
152
  describe('legacy (local project)', () => {
124
153
  describe('simple test execution', () => {
125
154
  beforeAll(async () => {