Skip to content

Commit

Permalink
Merge pull request #28 from ArnaudBuchholz/1.1.3
Browse files Browse the repository at this point in the history
1.1.3
  • Loading branch information
ArnaudBuchholz authored Nov 24, 2021
2 parents 9652a80 + 1a93918 commit ec7154e
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 170 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ You may also use :
| libs | | Folder(s) containing dependent libraries *(relative to `cwd`)*.<br/>Might be used multiple times, two syntaxes are supported :<ul><li>`-libs:path` adds `path` to the list of libraries, mapped directly under `/resources/`</li><li>`-libs:rel/=path` adds the `path` to the list of libraries, mapped under `/resources/rel/`</li></ul> |
| cache | `''` | Cache UI5 resources locally in the given folder *(empty to disable)* |
| webapp | `'webapp'` | base folder of the web application *(relative to `cwd`)* |
| testsuite | `'test/testsuite.qunit.html'` | path / URL to the testsuite file *(relative to `webapp`)* |
| pageFilter | `''` | [regexp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to select which pages to execute |
| pageParams | `''` | Parameters added to each page URL.<br/>For instance : `'sap-ui-theme=sap_belize&sap-ui-debug=true'` |
| pageTimeout | `0` | Limit the page execution time (ms), fails the page if it takes longer than the timeout (`0` to disable the timeout) |
Expand Down
14 changes: 14 additions & 0 deletions __mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = jest.requireActual('fs')

module.exports = {
...fs,
writeFile (path, content, options, callback) {
// This version is used only in unhandled
callback()
},
accessSync: path => {
if (path.includes('$NOT_EXISTING$')) {
throw new Error()
}
}
}
11 changes: 11 additions & 0 deletions __mocks__/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
jest.mock('child_process')
jest.mock('fs')

const EventEmitter = require('events')
const mockedOutput = new EventEmitter()

const output = jest.requireActual('../src/output')
Object.keys(output).forEach(name => {
mockedOutput[name] = function (...args) { this.emit(name, ...args) }
})
jest.mock('../src/output', () => mockedOutput)
14 changes: 0 additions & 14 deletions __tests__/src/browser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
jest.mock('child_process')
jest.mock('../../src/output', () => {
const EventEmitter = require('events')
class Output extends EventEmitter {
browserStart (...args) { this.emit('browserStart', ...args) }
browserStopped (...args) { this.emit('browserStopped', ...args) }
browserCapabilities (...args) { this.emit('browserCapabilities', ...args) }
browserTimeout (...args) { this.emit('browserTimeout', ...args) }
browserRetry (...args) { this.emit('browserRetry', ...args) }
browserClosed (...args) { this.emit('browserClosed', ...args) }
monitor (...args) { this.emit('monitor', ...args) }
}
return new Output()
})
const output = require('../../src/output')
const { join } = require('path')
const { _hook: hook } = require('child_process')
Expand Down
7 changes: 0 additions & 7 deletions __tests__/src/coverage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
jest.mock('child_process')
jest.mock('../../src/output', () => {
return {
nyc: jest.fn(),
monitor: jest.fn()
}
})
const { join } = require('path')
const jobFactory = require('../../src/job')
const { _hook: hook } = require('child_process')
Expand Down
27 changes: 22 additions & 5 deletions __tests__/src/job.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
jest.mock('../../src/output', () => {
return {
unexpectedOptionValue: jest.fn()
}
})
const { dirname, join } = require('path')
const jobFactory = require('../../src/job')
const cwd = '/test/project'
Expand Down Expand Up @@ -124,6 +119,28 @@ describe('src/job', () => {
expect(job.ui5).toStrictEqual('https://ui5.sap.com')
})

describe('Path parameters validation', () => {
it('webapp', () => {
const cwd = join(__dirname, '../cwd')
expect(() => jobFactory.fromCmdLine(cwd, [0, 0, '-webapp:$NOT_EXISTING$'])).toThrow()
})

it('browser', () => {
const cwd = join(__dirname, '../cwd')
expect(() => jobFactory.fromCmdLine(cwd, [0, 0, '-browser:$NOT_EXISTING$/cmd.js'])).toThrow()
})

it('testsuite', () => {
const cwd = join(__dirname, '../cwd')
expect(() => jobFactory.fromCmdLine(cwd, [0, 0, '-testsuite:$NOT_EXISTING$/testsuite.html'])).toThrow()
})

it('lib', () => {
const cwd = join(__dirname, '../cwd')
expect(() => jobFactory.fromCmdLine(cwd, [0, 0, '-libs:c=$NOT_EXISTING$/c'])).toThrow()
})
})

afterAll(() => {
expect(log.mock.calls.length).toStrictEqual(0)
expect(warn.mock.calls.length).toStrictEqual(0)
Expand Down
17 changes: 0 additions & 17 deletions __tests__/src/simulate.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
jest.mock('child_process')
jest.mock('../../src/output', () => {
return {
nyc: jest.fn(),
monitor: jest.fn(),
browserStart: jest.fn(),
browserStopped: jest.fn(),
endpoint: jest.fn(),
endpointError: jest.fn(),
timeSpent: jest.fn(),
globalTimeout: jest.fn(),
failFast: jest.fn(),
noTestPageFound: jest.fn(),
failedToCacheUI5resource: jest.fn(),
results: jest.fn()
}
})
const { join } = require('path')
const { mock } = require('reserve')
const jobFactory = require('../../src/job')
Expand Down
46 changes: 28 additions & 18 deletions __tests__/src/unhandled.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
jest.mock('../../src/output', () => {
return {
unhandled: jest.fn()
}
})
const output = require('../../src/output')
jest.mock('fs', () => {
return {
writeFile: jest.fn(),
promises: {
stat: jest.fn(),
mkdir: jest.fn()
}
}
})
const jobFactory = require('../../src/job')
const mappingFactory = require('../../src/unhandled')

Expand All @@ -22,12 +8,23 @@ describe('src/unhandled', () => {
let error
let unhandled

let unhandledCall = 0

function incUnhandledCall () {
++unhandledCall
}

beforeAll(() => {
log = jest.spyOn(console, 'log').mockImplementation()
warn = jest.spyOn(console, 'warn').mockImplementation()
error = jest.spyOn(console, 'error').mockImplementation()
output.on('unhandled', incUnhandledCall)
})

beforeEach(() => {
const job = jobFactory.fromCmdLine('/', [])
unhandled = mappingFactory(job)[0].custom
unhandledCall = 0
})

const expectedIgnores = [
Expand All @@ -39,27 +36,40 @@ describe('src/unhandled', () => {
expectedIgnores.forEach(url => {
it(`does not log known GET patterns (${url})`, () => {
expect(unhandled({ method: 'GET', url })).toStrictEqual(404)
expect(output.unhandled.mock.calls.length).toStrictEqual(0)
expect(unhandledCall).toStrictEqual(0)
})
})

const expectedWarnings = [
'any-mock-data-file.json',
'sourceFile.js'
]
expectedWarnings.forEach((url, index) => {
expectedWarnings.forEach(url => {
it(`warns about 404 GET (${url})`, () => {
expect(unhandled({ method: 'GET', url, headers: { referer: 'http://localhost:3475/test.html' } })).toStrictEqual(404)
expect(output.unhandled.mock.calls.length).toStrictEqual(1)
expect(unhandledCall).toStrictEqual(1)
})
})
it('Warns only once', () => {
expectedWarnings.forEach(url => {
expect(unhandled({ method: 'GET', url, headers: { referer: 'http://localhost:3475/test.html' } })).toStrictEqual(404)
})
expect(unhandledCall).toStrictEqual(1)
})

it('logs errors for any other verb', () => {
expect(unhandled({ method: 'POST', url: '/any_url', headers: { referer: 'http://localhost:3475/test.html' } })).toStrictEqual(500)
expect(output.unhandled.mock.calls.length).toStrictEqual(1)
expect(unhandledCall).toStrictEqual(1)
})

it('logs errors only once', () => {
expect(unhandled({ method: 'POST', url: '/any_url', headers: { referer: 'http://localhost:3475/test.html' } })).toStrictEqual(500)
expect(unhandled({ method: 'POST', url: '/any_other_url', headers: { referer: 'http://localhost:3475/test.html' } })).toStrictEqual(500)
expect(unhandledCall).toStrictEqual(1)
})

afterAll(() => {
output.off('unhandled', incUnhandledCall)
expect(log.mock.calls.length).toStrictEqual(0)
expect(warn.mock.calls.length).toStrictEqual(0)
expect(error.mock.calls.length).toStrictEqual(0)
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ async function main () {
})
}

main()
main().catch(reason => output.genericError(reason))
Loading

0 comments on commit ec7154e

Please sign in to comment.