-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(nodejs): upgrade to nodejs 20 (#4)
- change runtime to nodejs 20 for action - upgrade node packages - move logic from index.ts to main.ts for tests - update tests - run formatter - setup eslint - update actions to use node.js 20 BREAKING CHANGE: Upgrades to Node.js 20.x
- Loading branch information
Showing
15 changed files
with
34,433 additions
and
12,487 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,34 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"overrides": [ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"files": [ | ||
".eslintrc.{js,cjs}" | ||
], | ||
"parserOptions": { | ||
"sourceType": "script" | ||
} | ||
} | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
}, | ||
"ignorePatterns": ["dist/*.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
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 +1,2 @@ | ||
node_modules/ | ||
node_modules/ | ||
.idea/ |
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 +1 @@ | ||
v12 | ||
v20 |
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,59 +1,63 @@ | ||
import { getMinimumLength, getPullRequestDescription } from "../src/index"; | ||
import * as github from "@actions/github"; | ||
import { readFileSync } from "fs"; | ||
import { getDefaultSettings } from "http2"; | ||
|
||
describe("index", () => { | ||
describe("getMinimumIndex", () => { | ||
const name = "minLength"; | ||
it("returns the default length if one is not provided", () => { | ||
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = ""; | ||
const minLength = getMinimumLength(); | ||
expect(minLength).toBe(1); | ||
}); | ||
|
||
it("returns the provided min length if it is valid", () => { | ||
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "5"; | ||
const minLength = getMinimumLength(); | ||
expect(minLength).toBe(5); | ||
}); | ||
|
||
it("throws an error if the provided min length is not a number", () => { | ||
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "a"; | ||
expect(getMinimumLength).toThrowError("minLength must be a positive number"); | ||
}); | ||
import { getMinimumLength, getPullRequestDescription } from "../src/main"; | ||
|
||
describe("main", () => { | ||
describe("getMinimumIndex", () => { | ||
const name = "minLength"; | ||
it("returns the default length if one is not provided", () => { | ||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] = ""; | ||
const minLength = getMinimumLength(); | ||
expect(minLength).toBe(1); | ||
}); | ||
|
||
it("returns the provided min length if it is valid", () => { | ||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] = "5"; | ||
const minLength = getMinimumLength(); | ||
expect(minLength).toBe(5); | ||
}); | ||
|
||
it("throws an error if the provided min length is negative", () => { | ||
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "-4"; | ||
expect(getMinimumLength).toThrowError("minLength must be a positive number"); | ||
}); | ||
it("throws an error if the provided min length is not a number", () => { | ||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] = "a"; | ||
expect(getMinimumLength).toThrow("minLength must be a positive number"); | ||
}); | ||
|
||
describe("getPullRequestDescription", () => { | ||
it("gets a pull request event description", () => { | ||
process.env["GITHUB_EVENT_PATH"] = __dirname + "/valid-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }) | ||
); | ||
const description = getPullRequestDescription(); | ||
expect(description).toEqual("Valid Body"); | ||
}); | ||
it("throws an error if the provided min length is negative", () => { | ||
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] = "-4"; | ||
expect(getMinimumLength).toThrow("minLength must be a positive number"); | ||
}); | ||
}); | ||
|
||
describe("getPullRequestDescription", () => { | ||
it("gets a pull request event description", () => { | ||
process.env["GITHUB_EVENT_PATH"] = __dirname + "/valid-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" }), | ||
); | ||
const description = getPullRequestDescription(); | ||
expect(description).toEqual("Valid Body"); | ||
}); | ||
|
||
it("throws an error if the event is not a pull_request type", () => { | ||
process.env["GITHUB_EVENT_PATH"] = __dirname + "/wrong-event-type-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }) | ||
); | ||
expect(getPullRequestDescription).toThrowError("This action should only be run with Pull Request Events"); | ||
}); | ||
it("throws an error if the event is not a pull_request type", () => { | ||
process.env["GITHUB_EVENT_PATH"] = | ||
__dirname + "/wrong-event-type-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" }), | ||
); | ||
expect(getPullRequestDescription).toThrow( | ||
"This action should only be run with Pull Request Events", | ||
); | ||
}); | ||
|
||
it("throws an error if the description is not provided", () => { | ||
process.env["GITHUB_EVENT_PATH"] = __dirname + "/event-without-a-body.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }) | ||
); | ||
expect(getPullRequestDescription).toThrowError("This action should only be run with Pull Request Events"); | ||
}); | ||
it("throws an error if the description is not provided", () => { | ||
process.env["GITHUB_EVENT_PATH"] = | ||
__dirname + "/event-without-a-body.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" }), | ||
); | ||
expect(getPullRequestDescription).toThrow( | ||
"This action should only be run with Pull Request Events", | ||
); | ||
}); | ||
}) | ||
}); | ||
}); |
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
Oops, something went wrong.