Skip to content

Commit

Permalink
add ava tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed May 4, 2024
1 parent a4877a5 commit 71d8d4c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/eslint.yml → .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run ESLint
name: Run ESLint and ava tests

on:
push:
Expand All @@ -24,4 +24,22 @@ jobs:
- name: Install dependencies
run: npm i
- name: Run ESLint
run: npm run lint
run: npm run lint
ava:
name: Run ava tests
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Set up NodeJS LTS
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: npm i
- name: Run ava
run: npm run test
needs: [eslint]
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@
"type": "module",
"scripts": {
"ci": "tsx index.ts",
"lint": "tsc && eslint . --ext .ts"
"lint": "tsc && eslint . --ext .ts",
"test": "NODE_OPTIONS='--import=tsx --no-warnings' ava"
},
"ava": {
"files": [
"tests/**/*.test.ts"
],
"extensions": {
"ts": "module"
},
"workerThreads": false
},
"dependencies": {
"@actions/core": "^1.10.1",
"@octokit/rest": "^20.1.1",
"@types/luxon": "^3.4.2",
"@types/node": "^20.12.8",
"@types/semver": "^7.5.8",
"ava": "^6.1.2",
"commander": "^12.0.0",
"luxon": "^3.4.4",
"semver": "^7.6.0",
Expand Down
4 changes: 2 additions & 2 deletions sources/semver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Semver from 'semver'
import * as Luxon from 'luxon'

function GetDaysAfterNewYear(Now: Luxon.DateTime<true>) {
export function GetDaysAfterNewYear(Now: Luxon.DateTime<true>) {
const NewYear = Luxon.DateTime.utc(Now.year, 1, 1)
const Days = Now.diff(NewYear, 'days').days

Expand All @@ -14,7 +14,7 @@ export function UpdateDateVersion(Version: string) {
var Now = Luxon.DateTime.utc()

// Check if the date is updated and change.
if ((CurrentVersion.major !== Now.year) || (CurrentVersion.minor.toString() !== GetDaysAfterNewYear(Now).toString())) {
if ((CurrentVersion.major !== Number(`1${Now.year}`)) || (CurrentVersion.minor.toString() !== GetDaysAfterNewYear(Now).toString())) {
NewVersion += `1${Now.year}.`
NewVersion += `${GetDaysAfterNewYear(Now)}.`
NewVersion += '0'
Expand Down
14 changes: 14 additions & 0 deletions tests/semver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import test from 'ava'
import * as Luxon from 'luxon'
import {UpdateDateVersion, GetDaysAfterNewYear} from '../sources/semver.js'

test('UpdateDateVersion with current date', T => {
const Now = Luxon.DateTime.utc()
if (UpdateDateVersion(`1${Now.year}.${GetDaysAfterNewYear(Now)}.0`) !== '1' + Now.year + '.' + GetDaysAfterNewYear(Now) + '.1') {
T.fail()
}
if (UpdateDateVersion('2020.1.0') !== `1${Now.year}.${GetDaysAfterNewYear(Now)}.0`) {
T.fail()
}
T.pass()
})
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"include": [
"index.ts",
"sources/**/*.ts"
"sources/**/*.ts",
"tests/**/*.ts"
]
}

0 comments on commit 71d8d4c

Please sign in to comment.