-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cli): add tests for lb4 copyright command
- Loading branch information
1 parent
d8e576f
commit cc3cd67
Showing
7 changed files
with
145 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: myapp | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export class MyApplication {} |
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,30 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: @loopback/cli | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
const fs = require('fs'); | ||
|
||
exports.SANDBOX_FILES = [ | ||
{ | ||
path: 'src', | ||
file: 'application.ts', | ||
content: fs.readFileSync(require.resolve('./application.ts'), { | ||
encoding: 'utf-8', | ||
}), | ||
}, | ||
{ | ||
path: 'lib', | ||
file: 'no-header.js', | ||
content: fs.readFileSync(require.resolve('./no-header.js'), { | ||
encoding: 'utf-8', | ||
}), | ||
}, | ||
{ | ||
path: '', | ||
file: 'package.json', | ||
content: fs.readFileSync(require.resolve('./package.json.txt'), { | ||
encoding: 'utf-8', | ||
}), | ||
}, | ||
]; |
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,2 @@ | ||
// XYZ | ||
exports.xyz = {}; |
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,5 @@ | ||
{ | ||
"name": "myapp", | ||
"copyright.owner": "ACME Inc.", | ||
"license": "MIT" | ||
} |
87 changes: 87 additions & 0 deletions
87
packages/cli/test/integration/generators/copyright.integration.js
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,87 @@ | ||
// Copyright IBM Corp. 2020. All Rights Reserved. | ||
// Node module: @loopback/cli | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
const assert = require('yeoman-assert'); | ||
const testlab = require('@loopback/testlab'); | ||
const TestSandbox = testlab.TestSandbox; | ||
|
||
const generator = path.join(__dirname, '../../../generators/copyright'); | ||
const SANDBOX_FILES = require('../../fixtures/copyright').SANDBOX_FILES; | ||
const testUtils = require('../../test-utils'); | ||
|
||
// Test Sandbox | ||
const SANDBOX_PATH = path.resolve(__dirname, '..', '.sandbox'); | ||
const sandbox = new TestSandbox(SANDBOX_PATH); | ||
|
||
const year = new Date().getFullYear(); | ||
|
||
describe('lb4 copyright', function() { | ||
// eslint-disable-next-line no-invalid-this | ||
this.timeout(30000); | ||
|
||
beforeEach('reset sandbox', async () => { | ||
await sandbox.reset(); | ||
}); | ||
|
||
it('updates copyright/license headers with prompts', async () => { | ||
await testUtils | ||
.executeGenerator(generator) | ||
.inDir(SANDBOX_PATH, () => | ||
testUtils.givenLBProject(SANDBOX_PATH, { | ||
excludePackageJSON: true, | ||
additionalFiles: SANDBOX_FILES, | ||
}), | ||
) | ||
.withPrompts({owner: 'ACME Inc.', license: 'ISC'}) | ||
.withOptions({gitOnly: false}); | ||
|
||
assertApplicationTsFileUpdated(); | ||
assertJsFileUpdated(); | ||
}); | ||
|
||
it('updates copyright/license headers with options', async () => { | ||
await testUtils | ||
.executeGenerator(generator) | ||
.inDir(SANDBOX_PATH, () => | ||
testUtils.givenLBProject(SANDBOX_PATH, { | ||
excludePackageJSON: true, | ||
additionalFiles: SANDBOX_FILES, | ||
}), | ||
) | ||
.withOptions({owner: 'ACME Inc.', license: 'ISC', gitOnly: false}); | ||
|
||
assertApplicationTsFileUpdated(); | ||
assertJsFileUpdated(); | ||
}); | ||
}); | ||
|
||
function assertApplicationTsFileUpdated() { | ||
const file = path.join(SANDBOX_PATH, 'src', 'application.ts'); | ||
assertHeader(file); | ||
} | ||
|
||
function assertHeader(file) { | ||
assert.fileContent( | ||
file, | ||
`// Copyright ACME Inc. ${year}. All Rights Reserved.`, | ||
); | ||
assert.fileContent(file, '// Node module: myapp'); | ||
assert.fileContent( | ||
file, | ||
'// This file is licensed under the ISC License (ISC).', | ||
); | ||
assert.fileContent( | ||
file, | ||
'// License text available at https://opensource.org/licenses/ISC', | ||
); | ||
} | ||
|
||
function assertJsFileUpdated() { | ||
const file = path.join(SANDBOX_PATH, 'lib', 'no-header.js'); | ||
assertHeader(file); | ||
} |