-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: address feedback from yeoman update PR #476 #486
Open
gbockus-sf
wants to merge
1
commit into
main
Choose a base branch
from
gbockus/addressYeomanUpgradeFeedback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{ | ||
"version": "54.6.0", | ||
"npmClient": "yarn", | ||
"packages": [ | ||
"packages/*" | ||
] | ||
"packages": ["packages/*"] | ||
} |
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
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
127 changes: 127 additions & 0 deletions
127
packages/templates/test/generators/projectGenerator.test.ts
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,127 @@ | ||
/* | ||
* Copyright (c) 2022, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import * as fs from 'fs'; | ||
import { expect } from 'chai'; | ||
import ProjectGenerator from '../../src/generators/projectGenerator'; | ||
import * as YeomanEnvironment from 'yeoman-environment'; | ||
import { CreateUtil } from '../../src/utils'; | ||
import { assert, restore, SinonStub, stub } from 'sinon'; | ||
import { ProjectOptions } from '../../src'; | ||
|
||
describe('ProjectGenerator Unit Tests', () => { | ||
const testEnv = YeomanEnvironment.createEnv(); | ||
|
||
let mockProjectOptions: ProjectOptions & { env: any }; | ||
let checkInputsStub: SinonStub; | ||
let mkdirSyncStub: SinonStub; | ||
let existsSyncStub: SinonStub; | ||
|
||
beforeEach(() => { | ||
mockProjectOptions = { | ||
projectname: 'testProject', | ||
defaultpackagedir: 'some/other/dir', | ||
ns: 'imunique', | ||
template: 'standard', | ||
manifest: false, | ||
loginurl: 'https://never.gonna.log.you.in.com', | ||
env: testEnv | ||
}; | ||
checkInputsStub = stub(CreateUtil, 'checkInputs'); | ||
mkdirSyncStub = stub(fs, 'mkdirSync').returns(undefined); | ||
existsSyncStub = stub(fs, 'existsSync').returns(false); | ||
}); | ||
|
||
afterEach(() => { | ||
restore(); | ||
}); | ||
|
||
it('Should set the customInstallTask feature to false for the ProjectGenerator', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. went to add just this test, but then much us the file was uncovered so I went ahead and added some simple tests to cover the rest of the functionality. |
||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
expect((generator as any).features.customInstallTask).to.equal(false); | ||
}); | ||
|
||
it('Should attempt to validate template.', () => { | ||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
checkInputsStub.reset(); | ||
generator.validateOptions(); | ||
assert.calledOnce(checkInputsStub); | ||
assert.calledWith(checkInputsStub, 'standard'); | ||
}); | ||
|
||
describe('writing()', () => { | ||
it('Should attempt to write template files with standard template.', () => { | ||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
const copyTplStub = stub(generator.fs, 'copyTpl'); | ||
copyTplStub.returns(); | ||
generator.writing(); | ||
assert.callCount(copyTplStub, 18); | ||
assert.callCount(existsSyncStub, 36); | ||
assert.callCount(mkdirSyncStub, 18); | ||
}); | ||
|
||
it('Should attempt to write template files with empty template.', () => { | ||
mockProjectOptions.template = 'empty'; | ||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
const copyTplStub = stub(generator.fs, 'copyTpl'); | ||
copyTplStub.returns(); | ||
generator.writing(); | ||
assert.callCount(copyTplStub, 4); | ||
assert.callCount(existsSyncStub, 12); | ||
assert.callCount(mkdirSyncStub, 8); | ||
}); | ||
|
||
it('Should attempt to write template files with analytics template.', () => { | ||
mockProjectOptions.template = 'analytics'; | ||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
const copyTplStub = stub(generator.fs, 'copyTpl'); | ||
copyTplStub.returns(); | ||
generator.writing(); | ||
assert.callCount(copyTplStub, 16); | ||
assert.callCount(existsSyncStub, 27); | ||
assert.callCount(mkdirSyncStub, 11); | ||
}); | ||
}); | ||
|
||
describe('writing() with manifest', () => { | ||
beforeEach(() => { | ||
mockProjectOptions.manifest = true; | ||
}); | ||
|
||
it('Should attempt to write template files with standard template with manifest.', () => { | ||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
const copyTplStub = stub(generator.fs, 'copyTpl'); | ||
copyTplStub.returns(); | ||
generator.writing(); | ||
assert.callCount(copyTplStub, 19); | ||
assert.callCount(existsSyncStub, 37); | ||
assert.callCount(mkdirSyncStub, 18); | ||
}); | ||
|
||
it('Should attempt to write template files with empty template with manifest.', () => { | ||
mockProjectOptions.template = 'empty'; | ||
|
||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
const copyTplStub = stub(generator.fs, 'copyTpl'); | ||
copyTplStub.returns(); | ||
generator.writing(); | ||
assert.callCount(copyTplStub, 5); | ||
assert.callCount(existsSyncStub, 13); | ||
assert.callCount(mkdirSyncStub, 8); | ||
}); | ||
|
||
it('Should attempt to write template files with analytics template with manifest.', () => { | ||
mockProjectOptions.template = 'analytics'; | ||
const generator = new ProjectGenerator([], mockProjectOptions as any); | ||
const copyTplStub = stub(generator.fs, 'copyTpl'); | ||
copyTplStub.returns(); | ||
generator.writing(); | ||
assert.callCount(copyTplStub, 17); | ||
assert.callCount(existsSyncStub, 28); | ||
assert.callCount(mkdirSyncStub, 11); | ||
}); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same functionality with await/async