Skip to content

Commit

Permalink
Setup tests (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun authored Jan 24, 2024
1 parent 00cee9e commit 976cdf1
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 37 deletions.
84 changes: 51 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,62 @@ name: CI
on:
push:
paths-ignore:
- '*.md'
branches: [ master ]
- "*.md"
branches: [master]
tags:
- '*'
- "*"
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Extract Tag Name
run: echo "TAG_NAME=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
if: ${{ startsWith(github.ref, 'refs/tags') }}

- name: Publish SNAPSHOT
run: npm pack
if: ${{ !github.event.pull_request && env.TAG_NAME == '' }}

- name: Publish RELEASE
run: |
VERSION="$(echo "$TAG_NAME" | cut -d'v' -f 2)"
echo "Publish a release version=$VERSION for tag $TAG_NAME"
npm --no-git-tag-version --allow-same-version version $VERSION
npm pack
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
npm publish farjs-blessed-${VERSION}.tgz
if: ${{ env.TAG_NAME != '' }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Cache node_modules
uses: actions/cache@v3
with:
path: |
~/.npm
~/.nvm
~/work/blessed/blessed/node_modules
~/work/blessed/blessed/package-lock.json
key: ${{ runner.os }}-node_modules-cache-v1-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-node_modules-cache-v1-
- name: Extract Tag Name
run: echo "TAG_NAME=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
if: ${{ startsWith(github.ref, 'refs/tags') }}

- name: Run tests
run: |
npm i
npx tsc
npx quick-lint-js ./**/*.mjs
node ./test/all.mjs
if: ${{ env.TAG_NAME == '' }}

- name: Build SNAPSHOT
run: npm pack
if: ${{ env.TAG_NAME == '' }}

- name: Publish RELEASE
run: |
VERSION="$(echo "$TAG_NAME" | cut -d'v' -f 2)"
echo "Publish a release version=$VERSION for tag $TAG_NAME"
npm --no-git-tag-version --allow-same-version version $VERSION
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
npm publish
if: ${{ env.TAG_NAME != '' }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/ci_bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Bun CI

on:
push:
paths-ignore:
- "*.md"
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: "1.0.1"

- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
~/.bun/install/cache
~/work/blessed/blessed/bun.lockb
key: ${{ runner.os }}-bun-cache-v1-${{ hashFiles('package.json') }}
restore-keys: |
${{ runner.os }}-bun-cache-v1-
- name: Run tests
run: |
bun install
bun test
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**
**/*.js
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
"url": "https://github.com/viktor-podzigun"
}
],
"version": "0.2.0",
"version": "0.0.0",
"scripts": {
"lint": "quick-lint-js ./**/*.mjs ./**/*.ts",
"test": "tsc && bun test && node ./test/all.mjs"
},
"license": "MIT",
"main": "./lib/blessed.js",
"types": "./index.d.ts",
"preferGlobal": false,
"private": false,
"publishConfig": {
"access": "public"
},
Expand All @@ -39,7 +44,8 @@
"termcap"
],
"engines": {
"node": ">= 0.8.0"
"node": ">= 0.8.0",
"bun": ">=0.8"
},
"browserify": {
"transform": [
Expand All @@ -48,6 +54,7 @@
},
"devDependencies": {
"@types/blessed": "*",
"quick-lint-js": "^3.0.0",
"typescript": "^4.9.5"
}
}
1 change: 1 addition & 0 deletions test/all.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
await import("./lib/unicode.test.mjs");
19 changes: 19 additions & 0 deletions test/lib/unicode.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import assert from "node:assert/strict";
import { charWidth } from "../../lib/unicode.js";

const { describe, it } = await (async () => {
// @ts-ignore
const module = process.isBun ? "bun:test" : "node:test";
// @ts-ignore
return process.isBun // @ts-ignore
? Promise.resolve({ describe: (_, fn) => fn(), it: test })
: import(module);
})();

describe("unicode.test.mjs", () => {
it("should return char width", () => {
//when & then
assert.deepEqual(charWidth(0), 0);
assert.deepEqual(charWidth("0", 0), 1);
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"module": "node16",
"lib": ["ES6"],
"allowJs": true,
"checkJs": true,
"checkJs": false,
"importHelpers": true,
"strict": true,
"useUnknownInCatchVariables": false,
Expand Down

0 comments on commit 976cdf1

Please sign in to comment.