-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revise implementation and add unit test
- Loading branch information
1 parent
195c5c6
commit aa780f4
Showing
2 changed files
with
97 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const { buildArgs, normalizeFormat } = require('../../../src/cucumber-runner'); | ||
|
||
describe('buildArgs', () => { | ||
const cucumberBin = '/usr/local/bin/cucumber'; | ||
|
||
it('should build correct arguments with basic configuration', () => { | ||
const runCfg = { | ||
sauce: { | ||
metadata: {}, | ||
}, | ||
projectPath: '/project', | ||
assetsDir: '/project/assets', | ||
suite: { | ||
options: { | ||
paths: ['features/test.feature'], | ||
}, | ||
}, | ||
}; | ||
|
||
const result = buildArgs(runCfg, cucumberBin); | ||
|
||
expect(result).toEqual([ | ||
cucumberBin, | ||
'/project/features/test.feature', | ||
'--force-exit', | ||
'--require-module', | ||
'ts-node/register', | ||
'--format', | ||
'@saucelabs/cucumber-reporter', | ||
'--format-options', | ||
'{"upload":false,"outputFile":"/project/assets/sauce-test-report.json"}', | ||
]); | ||
}); | ||
}); | ||
|
||
describe('normalizeFormat', () => { | ||
const assetDir = '/project/assets'; | ||
|
||
it('should normalize formats with both quoted format type and path', () => { | ||
expect(normalizeFormat(`"html":"formatter/report.html"`, assetDir)).toBe( | ||
`"html":"/project/assets/formatter/report.html"`, | ||
); | ||
}); | ||
|
||
it('should normalize formats with only one pair of quote', () => { | ||
expect(normalizeFormat(`"html:formatter/report.html"`, assetDir)).toBe( | ||
`"html":"/project/assets/formatter/report.html"`, | ||
); | ||
}); | ||
|
||
it('should normalize formats with no quotes', () => { | ||
expect(normalizeFormat(`html:formatter/report.html`, assetDir)).toBe( | ||
`"html":"/project/assets/formatter/report.html"`, | ||
); | ||
}); | ||
|
||
it('should throw an error for invalid formats', () => { | ||
expect(() => | ||
normalizeFormat(`html-formatter/report.html`, assetDir), | ||
).toThrow('Invalid format: html-formatter/report.html'); | ||
expect(() => | ||
normalizeFormat(`"htmlformatter/report.html"`, assetDir), | ||
).toThrow('Invalid format: "htmlformatter/report.html"'); | ||
}); | ||
}); |