generated from salesforcecli/plugin-template-sf
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: remove header for 3PP * fix: generate unit test by default * chore: update comment * chore: add test for plugin generator * chore: maybe fix tests * chore: temporarily skip test
- Loading branch information
1 parent
eebb099
commit 05c60cd
Showing
9 changed files
with
204 additions
and
20 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* 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 path from 'path'; | ||
import helpers = require('yeoman-test'); | ||
import { expect } from 'chai'; | ||
import { readJson } from '../../../../src/util'; | ||
import { PackageJson } from '../../../../src/types'; | ||
|
||
describe('dev generate plugin', () => { | ||
// This test fails because the generator fails to remove the copyright headers on windows. | ||
// Once we move to a separate 3PP template, this will no longer be a problem. | ||
(process.platform !== 'win32' ? it : it.skip)('should generate a 3PP plugin', async () => { | ||
const runResult = await helpers | ||
.run(path.join(__dirname, '..', '..', '..', '..', 'src', 'generators', 'plugin.ts')) | ||
.withPrompts({ | ||
internal: false, | ||
name: 'my-plugin', | ||
description: 'my plugin description', | ||
author: 'my name', | ||
codeCoverage: '50%', | ||
}); | ||
|
||
runResult.assertFile(path.join(runResult.cwd, 'my-plugin', 'package.json')); | ||
runResult.assertFile(path.join(runResult.cwd, 'my-plugin', 'src', 'commands', 'hello', 'world.ts')); | ||
runResult.assertNoFile(path.join(runResult.cwd, 'my-plugin', 'CODE_OF_CONDUCT.md')); | ||
runResult.assertNoFile(path.join(runResult.cwd, 'my-plugin', 'command-snapshot.json')); | ||
runResult.assertNoFile(path.join(runResult.cwd, 'my-plugin', 'schemas', 'hello-world.json')); | ||
runResult.assertNoFile(path.join(runResult.cwd, 'my-plugin', '.git2gus', 'config.json')); | ||
|
||
const packageJson = readJson<PackageJson>(path.join(runResult.cwd, 'my-plugin', 'package.json')); | ||
expect(packageJson.name).to.equal('my-plugin'); | ||
expect(packageJson.author).to.equal('my name'); | ||
expect(packageJson.description).to.equal('my plugin description'); | ||
|
||
const scripts = Object.keys(packageJson.scripts); | ||
const keys = Object.keys(packageJson); | ||
|
||
expect(scripts).to.not.include('test:json-schema'); | ||
expect(scripts).to.not.include('test:deprecation-policy'); | ||
expect(scripts).to.not.include('test:command-reference'); | ||
expect(packageJson.scripts.posttest).to.equal('yarn lint'); | ||
expect(keys).to.not.include('homepage'); | ||
expect(keys).to.not.include('repository'); | ||
expect(keys).to.not.include('bugs'); | ||
|
||
runResult.assertNoFileContent( | ||
path.join(runResult.cwd, 'my-plugin', 'src', 'commands', 'hello', 'world.ts'), | ||
/Copyright/g | ||
); | ||
|
||
runResult.assertNoFileContent( | ||
path.join(runResult.cwd, 'my-plugin', '.eslintrc.js'), | ||
/eslint-config-salesforce-license/g | ||
); | ||
}); | ||
|
||
it('should generate a 2PP plugin', async () => { | ||
const runResult = await helpers | ||
.run(path.join(__dirname, '..', '..', '..', '..', 'src', 'generators', 'plugin.ts')) | ||
.withPrompts({ | ||
internal: true, | ||
name: 'plugin-test', | ||
description: 'my plugin description', | ||
hooks: ['sf:env:list', 'sf:env:display', 'sf:deploy', 'sf:logout'], | ||
}); | ||
|
||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'package.json')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'src', 'commands', 'hello', 'world.ts')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'CODE_OF_CONDUCT.md')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'command-snapshot.json')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'schemas', 'hello-world.json')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', '.git2gus', 'config.json')); | ||
|
||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'src', 'hooks', 'envList.ts')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'src', 'hooks', 'envDisplay.ts')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'src', 'hooks', 'deploy.ts')); | ||
runResult.assertFile(path.join(runResult.cwd, 'plugin-test', 'src', 'hooks', 'logout.ts')); | ||
|
||
const packageJson = readJson<PackageJson>(path.join(runResult.cwd, 'plugin-test', 'package.json')); | ||
expect(packageJson.name).to.equal('@salesforce/plugin-test'); | ||
expect(packageJson.author).to.equal('Salesforce'); | ||
expect(packageJson.description).to.equal('my plugin description'); | ||
expect(packageJson.oclif.hooks).to.deep.equal({ | ||
'sf:env:list': './lib/hooks/envList', | ||
'sf:env:display': './lib/hooks/envDisplay', | ||
'sf:deploy': './lib/hooks/deploy', | ||
'sf:logout': './lib/hooks/logout', | ||
}); | ||
|
||
const scripts = Object.keys(packageJson.scripts); | ||
const keys = Object.keys(packageJson); | ||
|
||
expect(scripts).to.include('test:json-schema'); | ||
expect(scripts).to.include('test:deprecation-policy'); | ||
expect(scripts).to.include('test:command-reference'); | ||
expect(keys).to.include('homepage'); | ||
expect(keys).to.include('repository'); | ||
expect(keys).to.include('bugs'); | ||
|
||
runResult.assertFileContent( | ||
path.join(runResult.cwd, 'plugin-test', 'src', 'commands', 'hello', 'world.ts'), | ||
/Copyright/g | ||
); | ||
|
||
runResult.assertFileContent( | ||
path.join(runResult.cwd, 'plugin-test', '.eslintrc.js'), | ||
/eslint-config-salesforce-license/g | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -1224,7 +1224,7 @@ | |
dependencies: | ||
"@sinonjs/commons" "^1.7.0" | ||
|
||
"@sinonjs/fake-timers@^7.1.2": | ||
"@sinonjs/fake-timers@^7.0.4", "@sinonjs/fake-timers@^7.1.2": | ||
version "7.1.2" | ||
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-7.1.2.tgz#2524eae70c4910edccf99b2f4e6efc5894aff7b5" | ||
integrity sha512-iQADsW4LBMISqZ6Ci1dupJL9pprqwcVFTcOsEmQOEhW+KLCVn/Y4Jrvg2k19fIHCp+iFprriYPTdRcQR8NbUPg== | ||
|
@@ -1264,7 +1264,7 @@ | |
lodash.get "^4.4.2" | ||
type-detect "^4.0.8" | ||
|
||
"@sinonjs/samsam@^6.0.2": | ||
"@sinonjs/samsam@^6.0.1", "@sinonjs/samsam@^6.0.2": | ||
version "6.1.1" | ||
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-6.1.1.tgz#627f7f4cbdb56e6419fa2c1a3e4751ce4f6a00b1" | ||
integrity sha512-cZ7rKJTLiE7u7Wi/v9Hc2fs3Ucc3jrWeMgPHbbTCeVAB2S0wOBbYlkJVeNSL04i7fdhT8wIbDq1zhC/PXTD2SA== | ||
|
@@ -1580,6 +1580,16 @@ | |
"@types/yeoman-environment" "*" | ||
rxjs "^6.4.0" | ||
|
||
"@types/yeoman-test@^4.0.3": | ||
version "4.0.3" | ||
resolved "https://registry.yarnpkg.com/@types/yeoman-test/-/yeoman-test-4.0.3.tgz#58959764bec68844b9eecd76e9be589c75eff15b" | ||
integrity sha512-CrR+wmWCVAmwU7/Px8WFlCFOi0wy/PoZUovkw4G0hiFNvQiGQn2I6xV4iHY9ebXlJ8w1u7sL9fnL9YkvB4Go0Q== | ||
dependencies: | ||
"@types/mem-fs" "*" | ||
"@types/mem-fs-editor" "*" | ||
"@types/yeoman-environment" "*" | ||
"@types/yeoman-generator" "*" | ||
|
||
"@types/yosay@^2.0.1": | ||
version "2.0.1" | ||
resolved "https://registry.yarnpkg.com/@types/yosay/-/yosay-2.0.1.tgz#320ff6ea4ba5d464a7c8ba1011d64fbf5562a1b0" | ||
|
@@ -5558,7 +5568,7 @@ marked@^4.0.16: | |
resolved "https://registry.yarnpkg.com/marked/-/marked-4.0.18.tgz#cd0ac54b2e5610cfb90e8fd46ccaa8292c9ed569" | ||
integrity sha512-wbLDJ7Zh0sqA0Vdg6aqlbT+yPxqLblpAZh1mK2+AO2twQkPywvvqQNfEPVwSSRjZ7dZcdeVBIAgiO7MMp3Dszw== | ||
|
||
"mem-fs-editor@^8.1.2 || ^9.0.0": | ||
"mem-fs-editor@^8.1.2 || ^9.0.0", mem-fs-editor@^9.0.0: | ||
version "9.5.0" | ||
resolved "https://registry.yarnpkg.com/mem-fs-editor/-/mem-fs-editor-9.5.0.tgz#9368724bd37f76eebfcf24d71fc6624b01588969" | ||
integrity sha512-7p+bBDqsSisO20YIZf2ntYvST27fFJINn7CKE21XdPUQDcLV62b/yB5sTOooQeEoiZ3rldZQ+4RfONgL/gbRoA== | ||
|
@@ -5959,7 +5969,7 @@ nise@^4.1.0: | |
just-extend "^4.0.2" | ||
path-to-regexp "^1.7.0" | ||
|
||
nise@^5.1.0: | ||
nise@^5.0.1, nise@^5.1.0: | ||
version "5.1.1" | ||
resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.1.tgz#ac4237e0d785ecfcb83e20f389185975da5c31f3" | ||
integrity sha512-yr5kW2THW1AkxVmCnKEh4nbYkJdB3I7LUkiUgOvEkOp414mc2UMaHMA7pjq1nYowhdoJZGwEKGaQVbxfpWj10A== | ||
|
@@ -7285,6 +7295,18 @@ [email protected]: | |
nise "^4.1.0" | ||
supports-color "^7.1.0" | ||
|
||
sinon@^10.0.0: | ||
version "10.0.1" | ||
resolved "https://registry.yarnpkg.com/sinon/-/sinon-10.0.1.tgz#0d1a13ecb86f658d15984f84273e57745b1f4c57" | ||
integrity sha512-1rf86mvW4Mt7JitEIgmNaLXaWnrWd/UrVKZZlL+kbeOujXVf9fmC4kQEQ/YeHoiIA23PLNngYWK+dngIx/AumA== | ||
dependencies: | ||
"@sinonjs/commons" "^1.8.1" | ||
"@sinonjs/fake-timers" "^7.0.4" | ||
"@sinonjs/samsam" "^6.0.1" | ||
diff "^4.0.2" | ||
nise "^5.0.1" | ||
supports-color "^7.1.0" | ||
|
||
sinon@^11.1.2: | ||
version "11.1.2" | ||
resolved "https://registry.yarnpkg.com/sinon/-/sinon-11.1.2.tgz#9e78850c747241d5c59d1614d8f9cbe8840e8674" | ||
|
@@ -7722,6 +7744,11 @@ tar@^6.0.2, tar@^6.1.0, tar@^6.1.11, tar@^6.1.2: | |
mkdirp "^1.0.3" | ||
yallist "^4.0.0" | ||
|
||
temp-dir@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-2.0.0.tgz#bde92b05bdfeb1516e804c9c00ad45177f31321e" | ||
integrity sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg== | ||
|
||
test-exclude@^6.0.0: | ||
version "6.0.0" | ||
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e" | ||
|
@@ -8530,6 +8557,17 @@ yeoman-generator@^5.6.1, yeoman-generator@^5.7.0: | |
sort-keys "^4.2.0" | ||
text-table "^0.2.0" | ||
|
||
yeoman-test@^6.3.0: | ||
version "6.3.0" | ||
resolved "https://registry.yarnpkg.com/yeoman-test/-/yeoman-test-6.3.0.tgz#c0b44562507dc40aa624719c8a24b2c49c2a196d" | ||
integrity sha512-FpaLV5AiVFlYe4pizAB/QLWc+5BSyttk/TcFQfi/r8g/rz290uqEkV4waN3rHEvP/DCmoMNSJykKTZNWL2y07g== | ||
dependencies: | ||
inquirer "^8.0.0" | ||
lodash "^4.17.21" | ||
mem-fs-editor "^9.0.0" | ||
sinon "^10.0.0" | ||
temp-dir "^2.0.0" | ||
|
||
[email protected]: | ||
version "3.1.1" | ||
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" | ||
|