Skip to content

Commit

Permalink
fix windows tests (#2)
Browse files Browse the repository at this point in the history
* attempt to fix windows tests for actionGenerator

* more fixes

* some more..

* last fix?
  • Loading branch information
moritzraho authored Jan 7, 2020
1 parent 56c16d4 commit 77499db
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"plugins": ["jest"],
"extends": ["standard", "plugin:jest/recommended"]
"extends": ["standard", "plugin:jest/recommended"],
"globals": {
"n": "readonly",
"r": "readonly"
}
}
18 changes: 9 additions & 9 deletions test/generators/add-action/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('run', () => {
// with skip prompt defaults to generic action
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('generic/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('generic/index.js')), expect.objectContaining({
'skip-prompt': true
}))
expect(installDependencies).toHaveBeenCalledTimes(1)
Expand All @@ -61,7 +61,7 @@ describe('run', () => {
// with skip prompt defaults to generic action
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('generic/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('generic/index.js')), expect.objectContaining({
'skip-prompt': true
}))
expect(installDependencies).toHaveBeenCalledTimes(0)
Expand All @@ -80,7 +80,7 @@ describe('run', () => {
name: 'actionGenerators',
validate: utils.atLeastOne,
choices: [
{ name: 'Generic', value: expect.stringContaining('generic/index.js'), checked: true }
{ name: 'Generic', value: expect.stringContaining(n('generic/index.js')), checked: true }
]
})
])
Expand All @@ -105,8 +105,8 @@ describe('run', () => {
name: 'actionGenerators',
validate: utils.atLeastOne,
choices: [
{ name: 'Adobe Analytics', value: expect.stringContaining('analytics/index.js') },
{ name: 'Generic', value: expect.stringContaining('generic/index.js'), checked: true }
{ name: 'Adobe Analytics', value: expect.stringContaining(n('analytics/index.js')) },
{ name: 'Generic', value: expect.stringContaining(n('generic/index.js')), checked: true }
]
})
])
Expand All @@ -131,10 +131,10 @@ describe('run', () => {
name: 'actionGenerators',
validate: utils.atLeastOne,
choices: [
{ name: 'Adobe Analytics', value: expect.stringContaining('analytics/index.js') },
{ name: 'Adobe Target', value: expect.stringContaining('target/index.js') },
{ name: 'Adobe Campaign Standard', value: expect.stringContaining('campaign-standard/index.js') },
{ name: 'Generic', value: expect.stringContaining('generic/index.js'), checked: true }
{ name: 'Adobe Analytics', value: expect.stringContaining(n('analytics/index.js')) },
{ name: 'Adobe Target', value: expect.stringContaining(n('target/index.js')) },
{ name: 'Adobe Campaign Standard', value: expect.stringContaining(n('campaign-standard/index.js')) },
{ name: 'Generic', value: expect.stringContaining(n('generic/index.js')), checked: true }
]
})
])
Expand Down
10 changes: 5 additions & 5 deletions test/generators/add-web-assets/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('run', () => {
const expectProjectName = path.basename(dir)

expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('raw/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('raw/index.js')), expect.objectContaining({
'skip-prompt': true,
'adobe-services': '',
'project-name': expectProjectName
Expand All @@ -62,7 +62,7 @@ describe('run', () => {
.withOptions({ 'skip-prompt': true, 'skip-install': false, 'project-name': 'fake' })

expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('raw/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('raw/index.js')), expect.objectContaining({
'skip-prompt': true,
'adobe-services': '',
'project-name': 'fake'
Expand All @@ -75,7 +75,7 @@ describe('run', () => {
.withOptions({ 'skip-prompt': true, 'skip-install': true, 'project-name': 'fake' })

expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('raw/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('raw/index.js')), expect.objectContaining({
'skip-prompt': true,
'adobe-services': '',
'project-name': 'fake'
Expand All @@ -88,7 +88,7 @@ describe('run', () => {
.withOptions({ 'skip-prompt': true, 'skip-install': false, 'project-name': 'fake', 'adobe-services': 'some,string' })

expect(composeWith).toHaveBeenCalledTimes(1)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('raw/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('raw/index.js')), expect.objectContaining({
'skip-prompt': true,
'adobe-services': 'some,string',
'project-name': 'fake'
Expand All @@ -106,7 +106,7 @@ describe('run', () => {
[expect.objectContaining({
type: 'list',
name: 'webAssetsGenerator',
choices: [{ name: 'Raw HTML/JS', value: expect.stringContaining('raw/index.js') }],
choices: [{ name: 'Raw HTML/JS', value: expect.stringContaining(n('raw/index.js')) }],
validate: utils.atLeastOne
})])

Expand Down
23 changes: 12 additions & 11 deletions test/generators/app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ describe('run', () => {
}

function expectDotEnv () {
assert.fileContent('.env', '# AIO_RUNTIME_AUTH=\n# AIO_RUNTIME_NAMESPACE=')
assert.fileContent('.env', '# AIO_RUNTIME_AUTH=')
assert.fileContent('.env', '# AIO_RUNTIME_NAMESPACE=')
}

test('--skip-prompt --project-name fake', async () => {
Expand All @@ -65,13 +66,13 @@ describe('run', () => {
assert.JSONFileContent('package.json', { name: 'fake-name', version: '0.0.1' })
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(2)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-web-assets/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-web-assets/index.js')), expect.objectContaining({
'skip-install': true,
'skip-prompt': true,
'adobe-services': '',
'project-name': 'fake-name'
}))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-action/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-action/index.js')), expect.objectContaining({
'skip-install': true,
'skip-prompt': true,
'adobe-services': ''
Expand All @@ -90,13 +91,13 @@ describe('run', () => {
assert.JSONFileContent('package.json', { name: expectedProjectName, version: '0.0.1' })
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(2)
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-web-assets/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-web-assets/index.js')), expect.objectContaining({
'skip-install': true,
'skip-prompt': true,
'adobe-services': 'some,string',
'project-name': expectedProjectName
}))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-action/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-action/index.js')), expect.objectContaining({
'skip-install': true,
'skip-prompt': true,
'adobe-services': 'some,string'
Expand All @@ -116,7 +117,7 @@ describe('run', () => {
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(1)

expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-action/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-action/index.js')), expect.objectContaining({
'skip-install': true,
'skip-prompt': false,
'adobe-services': 'some,string'
Expand All @@ -135,7 +136,7 @@ describe('run', () => {
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(1)

expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-web-assets/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-web-assets/index.js')), expect.objectContaining({
'skip-install': true,
'adobe-services': 'some,string',
'project-name': expectedProjectName
Expand All @@ -155,12 +156,12 @@ describe('run', () => {
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(2)

expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-web-assets/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-web-assets/index.js')), expect.objectContaining({
'skip-install': true,
'adobe-services': 'some,string',
'project-name': expectedProjectName
}))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-web-assets/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-web-assets/index.js')), expect.objectContaining({
'skip-install': true,
'adobe-services': 'some,string',
'project-name': expectedProjectName
Expand All @@ -178,12 +179,12 @@ describe('run', () => {
// make sure sub generators have been called
expect(composeWith).toHaveBeenCalledTimes(2)

expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-web-assets/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-web-assets/index.js')), expect.objectContaining({
'skip-install': true,
'adobe-services': '',
'project-name': expectedProjectName
}))
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining('add-web-assets/index.js'), expect.objectContaining({
expect(composeWith).toHaveBeenCalledWith(expect.stringContaining(n('add-web-assets/index.js')), expect.objectContaining({
'skip-install': true,
'adobe-services': '',
'project-name': expectedProjectName
Expand Down
6 changes: 6 additions & 0 deletions test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const path = require('path')

process.on('unhandledRejection', error => {
throw error
})

// quick normalization to test windows/unix paths
global.n = p => path.normalize(p)
global.r = p => path.resolve(p)
28 changes: 14 additions & 14 deletions test/lib/ActionGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js')

// 1. test copy action template to right destination
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith('/fakeTplDir/templateFile.js', `/fakeDestRoot/${constants.actionsDirname}/myAction/index.js`, {}, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`/fakeDestRoot/${constants.actionsDirname}/myAction/index.js`), {}, {}, {})
// 2. test manifest creation with action information
expect(actionGenerator.fs.write).toHaveBeenCalledWith('/fakeDestRoot/manifest.yml', yaml.safeDump({
expect(actionGenerator.fs.write).toHaveBeenCalledWith(n('/fakeDestRoot/manifest.yml'), yaml.safeDump({
packages: {
[constants.manifestPackagePlaceholder]: {
license: 'Apache-2.0',
actions: {
myAction: {
function: `${constants.actionsDirname}/myAction/index.js`, // relative path is important here
function: n(`${constants.actionsDirname}/myAction/index.js`), // relative path is important here
web: 'yes',
runtime: 'nodejs:10'
}
Expand All @@ -134,7 +134,7 @@ describe('implementation', () => {
}
}))
// 3. make sure wskdebug dependency was added to package.json
expect(actionGenerator.fs.writeJSON).toHaveBeenCalledWith('/fakeDestRoot/package.json', {
expect(actionGenerator.fs.writeJSON).toHaveBeenCalledWith(n('/fakeDestRoot/package.json'), {
devDependencies: {
'@adobe/wskdebug': '^1.1.0'
}
Expand All @@ -159,12 +159,12 @@ describe('implementation', () => {
}
actionGenerator.addAction('myAction', './templateFile.js')
// test manifest update with action information
expect(actionGenerator.fs.write).toHaveBeenCalledWith('/fakeDestRoot/manifest.yml', yaml.safeDump({
expect(actionGenerator.fs.write).toHaveBeenCalledWith(n('/fakeDestRoot/manifest.yml'), yaml.safeDump({
packages: {
[constants.manifestPackagePlaceholder]: {
actions: {
myAction: {
function: `${constants.actionsDirname}/myAction/index.js`, // relative path is important here
function: n(`${constants.actionsDirname}/myAction/index.js`), // relative path is important here
web: 'yes',
runtime: 'nodejs:10'
}
Expand All @@ -187,7 +187,7 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js', { dependencies: { abc: '1.2.3', def: '4.5.6' }, devDependencies: { xyz: '3.2.1', vuw: '6.5.4' } })

// dependencies are added to package.json + still adds wskdebug dependency
expect(actionGenerator.fs.writeJSON).toHaveBeenCalledWith('/fakeDestRoot/package.json', {
expect(actionGenerator.fs.writeJSON).toHaveBeenCalledWith(n('/fakeDestRoot/package.json'), {
dependencies: { abc: '1.2.3', def: '4.5.6' },
devDependencies: {
xyz: '3.2.1',
Expand All @@ -209,7 +209,7 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js', { tplContext: { fake: 'context', with: { fake: 'values' } } })

// 1. test copy action template to right destination
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith('/fakeTplDir/templateFile.js', `/fakeDestRoot/${constants.actionsDirname}/myAction/index.js`, { fake: 'context', with: { fake: 'values' } }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/templateFile.js'), n(`/fakeDestRoot/${constants.actionsDirname}/myAction/index.js`), { fake: 'context', with: { fake: 'values' } }, {}, {})
})

test('with actionManifestConfig option that also overwrite runtime action config', () => {
Expand All @@ -224,13 +224,13 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js', { actionManifestConfig: { runtime: 'fake:42', inputs: { fake: 'value' } } })

// test manifest update with action information
expect(actionGenerator.fs.write).toHaveBeenCalledWith('/fakeDestRoot/manifest.yml', yaml.safeDump({
expect(actionGenerator.fs.write).toHaveBeenCalledWith(n('/fakeDestRoot/manifest.yml'), yaml.safeDump({
packages: {
[constants.manifestPackagePlaceholder]: {
license: 'Apache-2.0',
actions: {
myAction: {
function: `${constants.actionsDirname}/myAction/index.js`, // relative path is important here
function: n(`${constants.actionsDirname}/myAction/index.js`), // relative path is important here
web: 'yes',
runtime: 'fake:42',
inputs: {
Expand All @@ -256,7 +256,7 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js', { dotenvStub: { label: 'fake label', vars: ['FAKE', 'FAKE2'] } })

// test manifest update with action information
expect(actionGenerator.fs.write).toHaveBeenCalledWith(`/fakeDestRoot/${constants.dotenvFilename}`, 'PREV=123\n\n## fake label\n#FAKE=\n#FAKE2=\n')
expect(actionGenerator.fs.write).toHaveBeenCalledWith(n(`/fakeDestRoot/${constants.dotenvFilename}`), 'PREV=123\n\n## fake label\n#FAKE=\n#FAKE2=\n')
})

test('with dotenvStub option but dotenv label is already set in dotenv (should ignore)', () => {
Expand All @@ -272,7 +272,7 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js', { dotenvStub: { label: 'fake label', vars: ['FAKE', 'FAKE2'] } })

// test manifest update with action information
expect(actionGenerator.fs.write).not.toHaveBeenCalledWith(`/fakeDestRoot/${constants.dotenvFilename}`, expect.any(String))
expect(actionGenerator.fs.write).not.toHaveBeenCalledWith(n(`/fakeDestRoot/${constants.dotenvFilename}`), expect.any(String))
})

test('with testFile option', () => {
Expand All @@ -287,7 +287,7 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js', { testFile: './template.test.js' })

// test manifest update with action information
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith('/fakeTplDir/template.test.js', `/fakeDestRoot/test/${constants.actionsDirname}/myAction.test.js`, { actionRelPath: `../../${constants.actionsDirname}/myAction/index.js` }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/template.test.js'), n(`/fakeDestRoot/test/${constants.actionsDirname}/myAction.test.js`), { actionRelPath: n(`../../${constants.actionsDirname}/myAction/index.js`) }, {}, {})
})

test('with testFile option and tplContext option (should append relative path to tested file to test template context)', () => {
Expand All @@ -302,7 +302,7 @@ describe('implementation', () => {
actionGenerator.addAction('myAction', './templateFile.js', { testFile: './template.test.js', tplContext: { fake: 'context', with: { fake: 'values' } } })

// test manifest update with action information
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith('/fakeTplDir/template.test.js', `/fakeDestRoot/test/${constants.actionsDirname}/myAction.test.js`, { actionRelPath: `../../${constants.actionsDirname}/myAction/index.js`, fake: 'context', with: { fake: 'values' } }, {}, {})
expect(actionGenerator.fs.copyTpl).toHaveBeenCalledWith(n('/fakeTplDir/template.test.js'), n(`/fakeDestRoot/test/${constants.actionsDirname}/myAction.test.js`), { actionRelPath: n(`../../${constants.actionsDirname}/myAction/index.js`), fake: 'context', with: { fake: 'values' } }, {}, {})
})
})
})

0 comments on commit 77499db

Please sign in to comment.