-
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.
chore(cli): add git test for lb4 copyright
- Loading branch information
1 parent
c8872ec
commit 56029c5
Showing
5 changed files
with
100 additions
and
1 deletion.
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
2 changes: 2 additions & 0 deletions
2
packages/cli/test/fixtures/copyright/single-package/.yo-rc.json
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 @@ | ||
{ | ||
} |
94 changes: 94 additions & 0 deletions
94
packages/cli/test/integration/generators/copyright-git.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,94 @@ | ||
// 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 fs = require('fs-extra'); | ||
const assert = require('yeoman-assert'); | ||
const git = require('../../../generators/copyright/git'); | ||
|
||
const generator = path.join(__dirname, '../../../generators/copyright'); | ||
const {spdxLicenseList} = require('../../../generators/copyright/header'); | ||
const FIXTURES = path.join(__dirname, '../../fixtures/copyright'); | ||
const LOCATION = 'single-package'; | ||
const PROJECT_ROOT = path.join(FIXTURES, LOCATION); | ||
const testUtils = require('../../test-utils'); | ||
|
||
// Establish the year(s) | ||
let year = new Date().getFullYear(); | ||
if (year !== 2020) year = `2020,${year}`; | ||
|
||
describe('lb4 copyright with git', function() { | ||
// eslint-disable-next-line no-invalid-this | ||
this.timeout(30000); | ||
|
||
before('add files not tracked by git', async () => { | ||
await fs.outputFile( | ||
path.join(PROJECT_ROOT, '.sandbox/file-not-tracked.js'), | ||
` | ||
// 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 | ||
function test() {} | ||
`, | ||
); | ||
}); | ||
|
||
after('reset sandbox', async () => { | ||
await fs.remove(path.join(PROJECT_ROOT, '.sandbox')); | ||
}); | ||
|
||
after('reset local changes ', async () => { | ||
// Revert changes made by the test against git-tracked fixtures | ||
await git(FIXTURES, `checkout -- ${LOCATION}`); | ||
}); | ||
|
||
it('updates copyright/license headers with options', async () => { | ||
await testUtils | ||
.executeGenerator(generator) | ||
.cd(PROJECT_ROOT) | ||
.withOptions({ | ||
owner: 'ACME Inc.', | ||
license: 'ISC', | ||
gitOnly: true, | ||
// Set `localConfigOnly` to skip searching for `.yo-rc.json` to change | ||
// the destination root | ||
localConfigOnly: true, | ||
}); | ||
|
||
// git tracked files are changed | ||
assertHeader( | ||
['src/application.ts', 'lib/no-header.js'], | ||
`// Copyright ACME Inc. ${year}. All Rights Reserved.`, | ||
'// Node module: myapp', | ||
`// This file is licensed under the ${spdxLicenseList['isc'].name}.`, | ||
`// License text available at ${spdxLicenseList['isc'].url}`, | ||
); | ||
|
||
// non git-tracked files are not touched | ||
assertHeader( | ||
['.sandbox/file-not-tracked.js'], | ||
'// 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', | ||
); | ||
}); | ||
}); | ||
|
||
function assertHeader(fileNames, ...expected) { | ||
if (typeof fileNames === 'string') { | ||
fileNames = [fileNames]; | ||
} | ||
for (const f of fileNames) { | ||
const file = path.join(FIXTURES, LOCATION, f); | ||
for (const line of expected) { | ||
assert.fileContent(file, line); | ||
} | ||
} | ||
} |