From 18558d8463f23d9e8a6a84fd9e08d395ec1eabec Mon Sep 17 00:00:00 2001 From: CookingWithCale Date: Mon, 18 Dec 2023 14:14:07 -0800 Subject: [PATCH] Fix unit test not working on GitHub #52.B Trying different GitHub Actions test script. --- .github/workflows/test.yml | 41 ++++++++++++++++++++++++-------------- Source/index.ts | 6 ++++-- Test/LID.test.ts | 10 +++++----- Test/LID64.test.ts | 6 +++--- Test/LLID.test.ts | 4 ++-- Test/Utilities.test.ts | 4 ++-- 6 files changed, 42 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b589cff..59d4c1c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,22 +1,33 @@ -name: Testing - -on: [pull_request] - +name: Jest +on: push jobs: - tests: + test: runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [14.x] - steps: - uses: actions/checkout@v2 - - name: Use Name.js ${{ matrix.node-version }} + - name: Setup Node.js uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node-version }} - - name: npm install + node-version: "12" + + # Speed up subsequent runs with caching + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + # Install required deps for action + - name: Install Dependencies run: npm install - - name: tests - run: npm run test + + # Finally, run our tests + - name: Run the tests + run: npm test \ No newline at end of file diff --git a/Source/index.ts b/Source/index.ts index 6f5e875..648afe4 100644 --- a/Source/index.ts +++ b/Source/index.ts @@ -638,7 +638,8 @@ export function LIDSource(lid: LID128) { } // Extracts the timestamp, ticker, and source from a LID64. -export function LIDPack(timestamp: number, ticker: number, source:bigint) +export function LIDPack(timestamp: bigint | number, ticker: bigint | number, + source:bigint) : LID128 { return (BigInt(timestamp) << (LIDTickerBitCount + LIDSourceBitCount)) | (BigInt(ticker) << LIDSourceBitCount) | source; @@ -743,7 +744,8 @@ export function LID64SourceId(): bigint { } // Extracts the timestamp, ticker, and source from a LID64. -export function LID64Pack(timestamp: number, ticker: number, source: bigint) +export function LID64Pack(timestamp: bigint | number, ticker: bigint | number, + source: bigint) : LID64 { return (BigInt(timestamp) << (64n - LID64TimestampBitCount)) | (BigInt(ticker) << LID64SourceBitCount) | diff --git a/Test/LID.test.ts b/Test/LID.test.ts index f6a168d..d68cd04 100644 --- a/Test/LID.test.ts +++ b/Test/LID.test.ts @@ -2,11 +2,11 @@ // http://github.com/AStarStartup/LinearId const { randomInt: rng } = require('crypto'); -const { BigIntInRange, BinaryPad, BinaryPadBitCount, HexPad, HexPadBitCount, +import { BigIntInRange, BinaryPad, BinaryPadBitCount, HexPad, HexPadBitCount, LIDPrint, LIDSourceBitCount, LIDTickerBitCount, LIDTimestampBitCount, - LIDNext, LIDPack, LIDTicker, LIDTimestamp, LIDSource, LIDUnpack, - NumberCountDecimals, NumberPad, TimestampSecondsNextBigInt -} = require('linearid'); + LIDNext, LIDPack, LIDTimestamp, LIDUnpack, NumberCountDecimals, NumberPad, + TimestampSecondsNextBigInt +} from '../Source'; import { expect, test } from '@jest/globals'; import { TestCount, TestLoopCount } from './Global'; @@ -102,5 +102,5 @@ test('LID.Test', () => { LIDCompare(timestamp_e, Received, '::LIDTimestamp::B', i); } } - expect(LIDPrint(LIDNext())).not.toBe(true); + expect(LIDPrint(LIDNext(rng))).not.toBe(true); }); diff --git a/Test/LID64.test.ts b/Test/LID64.test.ts index 7435402..86d8c76 100644 --- a/Test/LID64.test.ts +++ b/Test/LID64.test.ts @@ -2,11 +2,11 @@ // http://github.com/AStarStartup/LinearId const { randomInt: rng } = require('crypto'); -const { BigIntInRange, BinaryPad, BinaryPadBitCount, HexPad, HexPadBitCount, +import { BigIntInRange, BinaryPad, BinaryPadBitCount, HexPad, HexPadBitCount, LID64Print, LID64SourceBitCount, LID64TickerBitCount, LID64TimestampBitCount, LID64Next, LID64Pack, LID64Ticker, LID64Timestamp, LID64Source, LID64Unpack, NumberCountDecimals, NumberPad, TimestampSecondsNextBigInt -} = require('linearid'); +} from '../Source'; import { expect, test } from '@jest/globals'; import { TestCount, TestLoopCount } from './Global'; @@ -89,5 +89,5 @@ test('LID64.Test', () => { LID64Compare(timestamp_e, Received, '::LID64Timestamp::B', i); } } - expect(LID64Print(LID64Next())).not.toBe(true); + expect(LID64Print(LID64Next(rng))).not.toBe(true); }); diff --git a/Test/LLID.test.ts b/Test/LLID.test.ts index e05a05f..9844e35 100644 --- a/Test/LLID.test.ts +++ b/Test/LLID.test.ts @@ -2,10 +2,10 @@ // http://github.com/AStarStartup/LinearId const { randomInt: rng } = require('crypto'); -const { BigIntInRange, BinaryPad, BinaryPadBitCount, HexPad, HexPadBitCount, +import { BigIntInRange, BinaryPad, BinaryPadBitCount, HexPad, HexPadBitCount, LLIDPrint, LLIDTickerBitCount, LLIDTimestampBitCount, LLIDNext, LLIDPack, LLIDTimestamp, LLIDUnpack, NumberCountDecimals, NumberPad, - TimestampSecondsNextBigInt } = require('linearid'); + TimestampSecondsNextBigInt } from '../Source'; import { expect, test } from '@jest/globals'; import { TestCount, TestLoopCount, } from './Global'; diff --git a/Test/Utilities.test.ts b/Test/Utilities.test.ts index 5fd9244..7369d4d 100644 --- a/Test/Utilities.test.ts +++ b/Test/Utilities.test.ts @@ -2,11 +2,11 @@ // http://github.com/AStarStartup/LinearId const { randomInt } = require('crypto'); -const { BigIntCountDecimals, BigIntInBitRange, BigIntIsInBitRange, +import { BigIntCountDecimals, BigIntInBitRange, BigIntIsInBitRange, BigIntToBuffer, BigIntRandom, BinaryPad, BinaryPadBitCount, BufferToBigInt, ByteCountBits, HexToBigInt, HexToBuffer, HexPadBitCount, NumberCountBits, NumberCountBytes, NumberCountDecimals -} = require('linearid'); +} from '../Source'; import { expect, test } from '@jest/globals'; import { NumberInTestRange, TestBitCount, TestBitsUpTo, TestCount,