-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: use adobe linter, fix lints * fix: add unit tests * docs: update versions in README examples
- Loading branch information
1 parent
5a7a731
commit ad9dcea
Showing
9 changed files
with
213 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
uses: adobe/aio-reusable-workflows/.github/workflows/node.js.yml@main |
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,2 +1,3 @@ | ||
node_modules | ||
package-lock.json | ||
package-lock.json | ||
coverage |
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,30 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
module.exports = { | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'./index.js' | ||
], | ||
coverageThreshold: { | ||
global: { | ||
branches: 100, | ||
lines: 100, | ||
statements: 100, | ||
functions: 100 | ||
} | ||
}, | ||
testEnvironment: 'node', | ||
setupFilesAfterEnv: [ | ||
'./test/jest.setup.js' | ||
], | ||
clearMocks: true | ||
} |
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,94 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
const core = require('@actions/core') | ||
const exec = require('@actions/exec') | ||
|
||
jest.mock('@actions/core', () => ({ | ||
getInput: jest.fn(), | ||
setFailed: jest.fn() | ||
})) | ||
|
||
jest.mock('@actions/exec', () => ({ | ||
exec: jest.fn() | ||
})) | ||
|
||
beforeEach(() => { | ||
core.getInput.mockClear() | ||
}) | ||
|
||
describe('Install aio cli', () => { | ||
test('Success - aio cli install at latest', async () => { | ||
const os = 'macos-latest' | ||
const version = '' | ||
core.getInput.mockReturnValueOnce(os) | ||
core.getInput.mockReturnValueOnce(version) | ||
await jest.isolateModulesAsync(async () => { | ||
await require('../index') // run the action | ||
}) | ||
expect(exec.exec).toHaveBeenCalledTimes(2) | ||
expect(exec.exec).toHaveBeenCalledWith('npm install -g @adobe/aio-cli') | ||
expect(exec.exec).toHaveBeenCalledWith('aio --version') | ||
}) | ||
|
||
test('Success - aio cli install at specific version', async () => { | ||
const os = 'macos-latest' | ||
const version = '9.0.0' | ||
core.getInput.mockReturnValueOnce(os) | ||
core.getInput.mockReturnValueOnce(version) | ||
await jest.isolateModulesAsync(async () => { | ||
await require('../index') // run the action | ||
}) | ||
expect(exec.exec).toHaveBeenCalledTimes(2) | ||
expect(exec.exec).toHaveBeenCalledWith('npm install -g @adobe/aio-cli@9.0.0') | ||
expect(exec.exec).toHaveBeenCalledWith('aio --version') | ||
}) | ||
|
||
test('Success - aio cli install at latest on ubuntu', async () => { | ||
const os = 'ubuntu-latest' | ||
const version = '' | ||
core.getInput.mockReturnValueOnce(os) | ||
core.getInput.mockReturnValueOnce(version) | ||
await jest.isolateModulesAsync(async () => { | ||
await require('../index') // run the action | ||
}) | ||
expect(exec.exec).toHaveBeenCalledTimes(2) | ||
expect(exec.exec).toHaveBeenCalledWith('sudo npm install -g @adobe/aio-cli') | ||
expect(exec.exec).toHaveBeenCalledWith('aio --version') | ||
}) | ||
|
||
test('Success - aio cli install at specific version on ubuntu', async () => { | ||
const os = 'ubuntu-latest' | ||
const version = '9.0.0' | ||
core.getInput.mockReturnValueOnce(os) | ||
core.getInput.mockReturnValueOnce(version) | ||
await jest.isolateModulesAsync(async () => { | ||
await require('../index') // run the action | ||
}) | ||
expect(exec.exec).toHaveBeenCalledTimes(2) | ||
expect(exec.exec).toHaveBeenCalledWith('sudo npm install -g @adobe/aio-cli@9.0.0') | ||
expect(exec.exec).toHaveBeenCalledWith('aio --version') | ||
}) | ||
|
||
test('Failure - exec throws error', async () => { | ||
const os = 'macos-latest' | ||
const version = '90.1.1' | ||
core.getInput.mockReturnValueOnce(os) | ||
core.getInput.mockReturnValueOnce(version) | ||
exec.exec.mockRejectedValue(new Error('No matching version found for @adobe/aio-cli@90.1.1')) | ||
await jest.isolateModulesAsync(async () => { | ||
await require('../index') // run the action | ||
}) | ||
expect(exec.exec).toHaveBeenCalledTimes(1) | ||
expect(exec.exec).toHaveBeenCalledWith('npm install -g @adobe/aio-cli@90.1.1') | ||
expect(core.setFailed).toHaveBeenCalledWith('No matching version found for @adobe/aio-cli@90.1.1') | ||
}) | ||
}) |
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,31 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
jest.setTimeout(30000) | ||
|
||
const { stdout, stderr } = require('stdout-stderr') | ||
|
||
// trap console log | ||
beforeEach(() => { | ||
stdout.start() | ||
stderr.start() | ||
// change this if you need to see logs from stdout | ||
stdout.print = false | ||
}) | ||
|
||
afterEach(() => { | ||
stdout.stop() | ||
stderr.stop() | ||
}) | ||
|
||
process.on('unhandledRejection', error => { | ||
throw error | ||
}) |