mirror of https://github.com/aminya/setup-cpp
test: add unit tests
Used some code from https://github.com/aminya/install-cmake/
This commit is contained in:
parent
8ed361c47e
commit
41200c9f2f
|
@ -5,6 +5,7 @@ Thumbs.db
|
||||||
# Node
|
# Node
|
||||||
node_modules
|
node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
temp-*
|
||||||
|
|
||||||
# TypeScript
|
# TypeScript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
module.exports = {
|
||||||
|
preset: "ts-jest",
|
||||||
|
testEnvironment: "node",
|
||||||
|
testMatch: ["**/*.test.ts"],
|
||||||
|
// coverage
|
||||||
|
collectCoverageFrom: ["src/**/*.{ts,tsx}"],
|
||||||
|
coveragePathIgnorePatterns: ["assets", ".css.d.ts"],
|
||||||
|
verbose: true,
|
||||||
|
}
|
11
package.json
11
package.json
|
@ -14,8 +14,9 @@
|
||||||
"prepare": "npm run build",
|
"prepare": "npm run build",
|
||||||
"test.format": "prettier . --check",
|
"test.format": "prettier . --check",
|
||||||
"test.lint": "eslint .",
|
"test.lint": "eslint .",
|
||||||
"test": "run-p test.format test.lint test.tsc"
|
|
||||||
"test.tsc": "tsc --noEmit",
|
"test.tsc": "tsc --noEmit",
|
||||||
|
"test.unit": "jest",
|
||||||
|
"test": "run-p test.format test.lint test.tsc test.unit"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12.x"
|
"node": ">=12.x"
|
||||||
|
@ -32,19 +33,23 @@
|
||||||
"prettier": "prettier-config-atomic",
|
"prettier": "prettier-config-atomic",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/core": "^1.5.0",
|
"@actions/core": "^1.5.0",
|
||||||
|
"@actions/io": "^1.1.1",
|
||||||
"@actions/tool-cache": "^1.7.1",
|
"@actions/tool-cache": "^1.7.1",
|
||||||
|
"@types/jest": "^27.0.1",
|
||||||
"@types/node": "^16.9.1",
|
"@types/node": "^16.9.1",
|
||||||
"@types/semver": "^7.3.8",
|
"@types/semver": "^7.3.8",
|
||||||
"cross-env": "7.0.3",
|
"cross-env": "7.0.3",
|
||||||
"eslint-config-atomic": "^1.16.2",
|
"eslint-config-atomic": "^1.16.2",
|
||||||
"hasha": "^5.2.2",
|
"hasha": "^5.2.2",
|
||||||
|
"jest": "^27.2.0",
|
||||||
|
"npm-run-all2": "^5.0.2",
|
||||||
"parcel": "^2.0.0-rc.0",
|
"parcel": "^2.0.0-rc.0",
|
||||||
"prettier-config-atomic": "^2.0.5",
|
"prettier-config-atomic": "^2.0.5",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
"shx": "0.3.3",
|
"shx": "0.3.3",
|
||||||
"terser-config-atomic": "^0.1.1",
|
"terser-config-atomic": "^0.1.1",
|
||||||
"typescript": "^4.4.3",
|
"ts-jest": "^27.0.5",
|
||||||
"npm-run-all2": "^5.0.2"
|
"typescript": "^4.4.3"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github-actions",
|
"github-actions",
|
||||||
|
|
1728
pnpm-lock.yaml
1728
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,41 @@
|
||||||
|
import * as process from "process"
|
||||||
|
import * as path from "path"
|
||||||
|
import * as io from "@actions/io"
|
||||||
|
import { setupCmake } from "../cmake"
|
||||||
|
import { spawnSync as spawn } from "child_process"
|
||||||
|
import { tmpdir } from "os"
|
||||||
|
|
||||||
|
jest.setTimeout(30 * 1000)
|
||||||
|
|
||||||
|
const tempDirectory = path.join(tmpdir(), "setup-cpp", "setup-cmake")
|
||||||
|
|
||||||
|
describe("setup-cmake", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await io.rmRF(tempDirectory)
|
||||||
|
await io.mkdirP(tempDirectory)
|
||||||
|
process.env.INPUT_DESTINATION = tempDirectory
|
||||||
|
process.env.GITHUB_WORKSPACE = tempDirectory
|
||||||
|
process.env.RUNNER_TEMP = path.join(tempDirectory, "temp")
|
||||||
|
process.env.RUNNER_TOOL_CACHE = path.join(tempDirectory, "tempToolCache")
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
try {
|
||||||
|
await io.rmRF(tempDirectory)
|
||||||
|
} catch {
|
||||||
|
console.log("Failed to remove test directories")
|
||||||
|
}
|
||||||
|
}, 100000)
|
||||||
|
|
||||||
|
it("should download CMake", async () => {
|
||||||
|
const cmakePath = await setupCmake("3.20.2")
|
||||||
|
expect(cmakePath).toBeDefined()
|
||||||
|
expect(cmakePath).not.toHaveLength(0)
|
||||||
|
|
||||||
|
const { status, error } = spawn(cmakePath, ["--version"], {
|
||||||
|
encoding: "utf8",
|
||||||
|
})
|
||||||
|
expect(error).toBeUndefined()
|
||||||
|
expect(status).toBe(0)
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,40 @@
|
||||||
|
import * as process from "process"
|
||||||
|
import * as path from "path"
|
||||||
|
import * as io from "@actions/io"
|
||||||
|
import { setupNinja } from "../ninja"
|
||||||
|
import { spawnSync as spawn } from "child_process"
|
||||||
|
import { tmpdir } from "os"
|
||||||
|
|
||||||
|
const tempDirectory = path.join(tmpdir(), "setup-cpp", "setup-ninja")
|
||||||
|
|
||||||
|
jest.setTimeout(30 * 1000)
|
||||||
|
|
||||||
|
describe("setup-ninja", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await io.rmRF(tempDirectory)
|
||||||
|
await io.mkdirP(tempDirectory)
|
||||||
|
process.env.INPUT_DESTINATION = tempDirectory
|
||||||
|
process.env.GITHUB_WORKSPACE = tempDirectory
|
||||||
|
process.env.RUNNER_TEMP = path.join(tempDirectory, "temp")
|
||||||
|
process.env.RUNNER_TOOL_CACHE = path.join(tempDirectory, "tempToolCache")
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
try {
|
||||||
|
await io.rmRF(tempDirectory)
|
||||||
|
} catch {
|
||||||
|
console.error("Failed to remove test directories")
|
||||||
|
}
|
||||||
|
}, 100000)
|
||||||
|
|
||||||
|
it("should fetch Ninja 1.10.2", async () => {
|
||||||
|
const ninjaPath = await setupNinja("1.10.2")
|
||||||
|
expect(ninjaPath).toBeDefined()
|
||||||
|
expect(ninjaPath).not.toHaveLength(0)
|
||||||
|
|
||||||
|
const { status } = spawn(ninjaPath, ["--version"], {
|
||||||
|
encoding: "utf8",
|
||||||
|
})
|
||||||
|
expect(status).toBe(0)
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue