-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added unit testing using jest * Added job to build and test using npm Signed-off-by: Saurabh Kamat <[email protected]> --------- Signed-off-by: Saurabh Kamat <[email protected]>
- Loading branch information
Showing
7 changed files
with
4,261 additions
and
1,099 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
set -euxo pipefail | ||
|
||
npm install -g codecov | ||
|
||
# When running inside a Docker container, by default, we're root and all files belond to root. | ||
# However, calling the npm scripts (build, etc.) with 'npm run ...' runs the commands as user | ||
# ID=1001, which means we can't open or write to any files. Therefore, if we're in Docker, chown | ||
# everything under /__w (which is the workspace directory on the host: /home/runner/work) to user | ||
# ID=1001. See: | ||
# * https://github.com/ros-tooling/setup-ros/pull/521 | ||
# * https://github.com/npm/cli/issues/4589 | ||
docker_workdir="/__w" | ||
if [ -d "${docker_workdir}" ]; then | ||
chown -R 1001:1001 "${docker_workdir}" | ||
fi | ||
|
||
npm ci | ||
npm run build | ||
npm test | ||
|
||
# Upload code coverage to CodeCov, but do not fail the CI if CodeCov upload | ||
# fails as the service is sometimes flaky. | ||
codecov -f ./coverage/coverage-final.json || 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,33 @@ on: | |
push: | ||
branches: | ||
- main | ||
- "releases/*" | ||
- 'releases/*' | ||
schedule: | ||
# Run the CI automatically twice per day to look for flakyness. | ||
- cron: "0 */12 * * *" | ||
- cron: '0 */12 * * *' | ||
defaults: | ||
run: | ||
shell: bash | ||
jobs: | ||
test_action_linux: | ||
name: 'Run unit test on action' | ||
runs-on: ubuntu-latest | ||
container: | ||
image: ${{ matrix.docker_image }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
docker_image: | ||
- ubuntu:focal | ||
- ubuntu:jammy | ||
- ubuntu:noble | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/[email protected] | ||
with: | ||
node-version: '20.x' | ||
- run: .github/workflows/build-and-test.sh | ||
|
||
test_gazebo_install_ubuntu: | ||
name: 'Check installation of Gazebo on Ubuntu' | ||
runs-on: ubuntu-latest | ||
|
@@ -45,7 +64,7 @@ jobs: | |
- uses: actions/checkout@v4 | ||
- uses: actions/[email protected] | ||
with: | ||
node-version: "20.x" | ||
node-version: '20.x' | ||
- name: 'Check Gazebo installation on Ubuntu runner' | ||
uses: ./ | ||
with: | ||
|
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,70 @@ | ||
import * as core from "@actions/core"; | ||
import * as exec from "@actions/exec"; | ||
|
||
import * as linux from "../src/setup-gazebo-linux"; | ||
import * as utils from "../src/utils"; | ||
|
||
describe("workflow test without input", () => { | ||
beforeAll(() => { | ||
jest.spyOn(exec, "exec").mockImplementation(jest.fn()); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("run Linux workflow without", async () => { | ||
await expect(linux.runLinux()).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
describe("workflow test with a invalid distro input", () => { | ||
beforeAll(() => { | ||
jest.spyOn(exec, "exec").mockImplementation(jest.fn()); | ||
jest.spyOn(core, "getInput").mockReturnValue("dome"); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("run Linux workflow without", async () => { | ||
await expect(linux.runLinux()).rejects.toThrow(); | ||
}); | ||
}); | ||
|
||
describe("workflow test with a valid distro input", () => { | ||
beforeAll(() => { | ||
jest.spyOn(exec, "exec").mockImplementation(jest.fn()); | ||
jest.spyOn(core, "getInput").mockReturnValue("harmonic"); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("run Linux workflow without", async () => { | ||
await expect(linux.runLinux()).resolves.not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe("validate distribution test", () => { | ||
it("test valid distro", async () => { | ||
await expect(utils.validateDistro(["citadel"])).toBe(true); | ||
await expect(utils.validateDistro(["fortress"])).toBe(true); | ||
await expect(utils.validateDistro(["garden"])).toBe(true); | ||
await expect(utils.validateDistro(["harmonic"])).toBe(true); | ||
await expect(utils.validateDistro(["fortress", "garden"])).toBe(true); | ||
}); | ||
it("test invalid distro", async () => { | ||
await expect(utils.validateDistro(["acropolis"])).toBe(false); | ||
await expect(utils.validateDistro(["blueprint"])).toBe(false); | ||
await expect(utils.validateDistro(["dome"])).toBe(false); | ||
await expect(utils.validateDistro(["edifice"])).toBe(false); | ||
await expect(utils.validateDistro(["doesNotExist"])).toBe(false); | ||
await expect(utils.validateDistro(["dome", "fortress"])).toBe(false); | ||
await expect(utils.validateDistro(["citadel", "edifice", "harmonic"])).toBe( | ||
false, | ||
); | ||
}); | ||
}); |
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,12 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
moduleFileExtensions: ["js", "ts"], | ||
testEnvironment: "node", | ||
testMatch: ["**/*.test.ts"], | ||
testRunner: "jest-circus/runner", | ||
transform: { | ||
"^.+\\.ts$": "ts-jest", | ||
}, | ||
transformIgnorePatterns: ["^.+\\.js$"], | ||
verbose: true, | ||
}; |
Oops, something went wrong.