Skip to content

Commit

Permalink
test(actions): add tests for has-installed-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
neilime committed Aug 24, 2023
1 parent ab693e2 commit 13eeb29
Show file tree
Hide file tree
Showing 10 changed files with 27,047 additions and 10 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/__test-action-get-package-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- run: touch yarn.lock
- run: rm -f package-lock.json

- id: get-package-manager
uses: ./actions/get-package-manager
Expand All @@ -28,9 +28,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- run: |
rm -f yarn.lock
touch package-lock.json
- run: rm -f yarn.lock

- id: get-package-manager
uses: ./actions/get-package-manager
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/__test-action-has-installed-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Internal - Tests for "has-installed-dependencies" action

on:
workflow_call:

jobs:
test-yarn:
name: Tests with Yarn package manager
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- run: rm -f package-lock.json

- uses: ./actions/setup-node

- id: has-installed-dependencies
uses: ./actions/has-installed-dependencies
with:
dependencies: |
nx
gatsby
storybook
prettier
unknown
- name: Check "has-installed-dependencies" outputs
uses: actions/github-script@v6
with:
script: |
const assert = require("assert");
const installedDependenciesOutput = `${{ steps.has-installed-dependencies.outputs.installed-dependencies }}`;
assert(installedDependenciesOutput.length, `"installed-dependencies" output is empty`);
// Check if is valid Json
let installedDependencies = null;
try {
installedDependencies = JSON.parse(installedDependenciesOutput);
} catch (error) {
throw new Error(`"installed-dependencies" output is not a valid JSON: ${error}`);
}
const expectedResult = {
nx: true,
gatsby: true,
storybook: true,
prettier: true,
unknown: false,
};
assert.equal(
installedDependencies,
expectedResult,
`"installed-dependencies" output is not valid`
);
test-npm:
name: Tests with Npm package manager
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- run: rm -f yarn.lock

- id: has-installed-dependencies
uses: ./actions/has-installed-dependencies
with:
dependencies: |
nx
gatsby
storybook
prettier
unknown
- name: Check "has-installed-dependencies" outputs
uses: actions/github-script@v6
with:
script: |
// jscpd:ignore-start
const assert = require("assert");
const installedDependenciesOutput = `${{ steps.has-installed-dependencies.outputs.installed-dependencies }}`;
assert(installedDependenciesOutput.length, `"installed-dependencies" output is empty`);
// Check if is valid Json
let installedDependencies = null;
try {
installedDependencies = JSON.parse(installedDependenciesOutput);
} catch (error) {
throw new Error(`"installed-dependencies" output is not a valid JSON: ${error}`);
}
const expectedResult = {
nx: true,
gatsby: true,
storybook: true,
prettier: true,
unknown: false,
};
assert.equal(
installedDependencies,
expectedResult,
`"installed-dependencies" output is not valid`
);
// jscpd:ignore-end
3 changes: 1 addition & 2 deletions .github/workflows/__test-action-setup-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3

- run: |
touch yarn.lock
rm -f package-lock.json
echo "lts/*" > .nvmrc
- id: setup-node
Expand All @@ -32,7 +32,6 @@ jobs:

- run: |
rm -f yarn.lock
echo "{}" > package-lock.json
echo "lts/*" > .nvmrc
- id: setup-node
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
2 changes: 1 addition & 1 deletion actions/get-package-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- end title -->
<!-- start description -->

Action to detect the package manager used. Supports Yarn and NPM
Action to detect the package manager used. Supports Yarn and npm

<!-- end description -->
<!-- start contents -->
Expand Down
2 changes: 1 addition & 1 deletion actions/get-package-manager/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Get package manager"
description: "Action to detect the package manager used. Supports Yarn and NPM"
description: "Action to detect the package manager used. Supports Yarn and npm"
author: Hoverkraft
branding:
icon: package
Expand Down
2 changes: 1 addition & 1 deletion actions/has-installed-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ runs:
const installedDependencies = new Map();
for (const dependency in dependencies) {
for (const dependency of dependencies) {
let command = `${{ steps.get-package-manager.outputs.package-manager }} list --depth=1" --pattern "${dependency}"`;
Expand Down
Loading

0 comments on commit 13eeb29

Please sign in to comment.