Skip to content

Commit

Permalink
Adapt CI. Add very basic tests using @cross/test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Oct 2, 2024
1 parent a641594 commit cdec278
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 279 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/bun.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/deno.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/node.js.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
branches: [main, dev, dev-9.0]
pull_request:
branches: [main, dev, dev-9.0]

jobs:
deno_ci:
uses: cross-org/workflows/.github/workflows/deno-ci.yml@main
with:
entrypoint: src/croner.ts
lint_docs: false
bun_ci:
uses: cross-org/workflows/.github/workflows/bun-ci.yml@main
node_ci:
uses: cross-org/workflows/.github/workflows/node-ci.yml@main
with:
test_target: "test/*.test.ts"
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ Quick examples:

```javascript
// Basic: Run a function at the interval defined by a cron expression
const job = Cron('*/5 * * * * *', () => {
const job = new Cron('*/5 * * * * *', () => {
console.log('This will run every fifth second');
});

// Enumeration: What dates do the next 100 sundays occur on?
const nextSundays = Cron('0 0 0 * * 7').nextRuns(100);
const nextSundays = new Cron('0 0 0 * * 7').nextRuns(100);
console.log(nextSundays);

// Days left to a specific date
const msLeft = Cron('59 59 23 24 DEC *').nextRun() - new Date();
const msLeft = new Cron('59 59 23 24 DEC *').nextRun() - new Date();
console.log(Math.floor(msLeft/1000/3600/24) + " days left to next christmas eve");

// Run a function at a specific date/time using a non-local timezone (time is ISO 8601 local time)
// This will run 2024-01-23 00:00:00 according to the time in Asia/Kolkata
Cron('2024-01-23T00:00:00', { timezone: 'Asia/Kolkata' }, () => { console.log('Yay!') });
new Cron('2024-01-23T00:00:00', { timezone: 'Asia/Kolkata' }, () => { console.log('Yay!') });

```

Expand Down Expand Up @@ -96,13 +96,13 @@ Cron takes three arguments
// - First: Cron pattern, js date object (fire once), or ISO 8601 time string (fire once)
// - Second: Options (optional)
// - Third: Function run trigger (optional)
const job = Cron("* * * * * *", { maxRuns: 1 }, () => {} );
const job = new Cron("* * * * * *", { maxRuns: 1 }, () => {} );

// If function is omitted in constructor, it can be scheduled later
job.schedule(job, /* optional */ context) => {});
```

The job will be sceduled to run at next matching time unless you supply option `{ paused: true }`. The `Cron(...)` constructor will return a Cron instance, later called `job`, which have a couple of methods and properties listed below.
The job will be sceduled to run at next matching time unless you supply option `{ paused: true }`. The `new Cron(...)` constructor will return a Cron instance, later called `job`, which have a couple of methods and properties listed below.

#### Status

Expand Down
129 changes: 0 additions & 129 deletions test/basics.cjs → _oldtest/basics.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ let assert = require("uvu/assert"),
sleep = require("./util/sleep.cjs");

module.exports = function (Cron, test, scheduledJobs) {
test("new Cron(...) should not throw", function () {
assert.not.throws(() => {
let scheduler = new Cron("* * * * * *");
scheduler.nextRun();
});
});

test("cron(...) without `new` should not throw", function () {
assert.not.throws(() => {
let scheduler = Cron("* * * * * *");
scheduler.nextRun();
});
});

test("Scheduling two functions with the same instance is not allowed", function () {
assert.throws(() => {
Expand All @@ -29,122 +16,6 @@ module.exports = function (Cron, test, scheduledJobs) {
});
});

test("Scheduling two functions with the same instance is not allowed (shorthand)", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * * *", (self) => {
self.stop();
});
scheduler.schedule((self) => {
self.stop();
});
});
});

test("Array passed as next date should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * * *");
scheduler.nextRun([]);
});
});

test("31st february should not be found", function () {
assert.not.throws(() => {
let scheduler = new Cron("* * * 31 2 *");
assert.equal(scheduler.nextRun(), null);
});
});

test("Too high days should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * 32 * *");
scheduler.nextRun();
});
});

test("Too low days should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * 0 * *");
scheduler.nextRun();
});
});

test("Valid months should not throw", function () {
assert.not.throws(() => {
let scheduler = new Cron("* * * * 1,2,3,4,5,6,7,8,9,10,11,12 *");
scheduler.nextRun();
});
});

test("Too high months should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * 7-13 *");
scheduler.nextRun();
});
});

test("Too low months should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * 0-3 *");
scheduler.nextRun();
});
});

test("Valid weekdays should not throw", function () {
assert.not.throws(() => {
let scheduler = new Cron("* * * * * 0,1,2,3,4,5,6,7");
scheduler.nextRun();
});
});

test("Too high weekday should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * * 8");
scheduler.nextRun();
});
});

test("Too low weekday should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * * -1");
scheduler.nextRun();
});
});

test("Too high hours minute should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * 0,23,24 * * *");
scheduler.nextRun();
});
});

test("Options as second argument should not throw", function () {
assert.not.throws(() => {
let scheduler = new Cron("* * * * * *", { maxRuns: 1 });
scheduler.nextRun();
});
});

test("Options as third argument should not throw", function () {
assert.not.throws(() => {
let scheduler = new Cron("* * * * * *", () => {}, { maxRuns: 1 });
scheduler.nextRun();
});
});

test("Text as second argument should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * * *", "bogus", { maxRuns: 1 });
scheduler.nextRun();
});
});

test("Text as third argument should throw", function () {
assert.throws(() => {
let scheduler = new Cron("* * * * * *", { maxRuns: 1 }, "bogus");
scheduler.nextRun();
});
});

test(
"Context is passed",
timeout(2000, (resolve, reject) => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 6 additions & 5 deletions build/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import esbuild from "esbuild";
import { dtsPlugin } from "esbuild-plugin-d.ts";
import { exit } from "@cross/utils";
import { dirname, fromFileUrl, resolve } from "@std/path";
// import type { cp } from "@cross/fs";
import { cp } from "@cross/fs";

let relativeProjectRoot = "../";
const outputFolder = "dist";
Expand All @@ -13,9 +13,7 @@ relativeProjectRoot = resolve(currentScriptDir, relativeProjectRoot);
const tsConfig = {
declaration: true,
compilerOptions: {
rootDir: resolve(relativeProjectRoot, "src"),
outDir: resolve(relativeProjectRoot, "dist"),
emitDeclarationOnly: true,
outFile: resolve(relativeProjectRoot, "dist", "croner.d.ts"),
allowImportingTsExtensions: true,
target: "ES6",
},
Expand Down Expand Up @@ -71,4 +69,7 @@ try {
}

// Copy .d.ts to .d.cts
//await cp(resolve(relativeProjectRoot, outputFolder, 'croner.d.ts'),resolve(relativeProjectRoot, outputFolder, 'croner.d.cts'));
await cp(
resolve(relativeProjectRoot, outputFolder, "croner.d.ts"),
resolve(relativeProjectRoot, outputFolder, "croner.d.cts"),
);
3 changes: 2 additions & 1 deletion build/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ async function generatePackageJson() {

// Define package.json template
const packageJson = {
name: denoConfig.name,
name: "croner",
//name: denoConfig.name,
version: denoConfig.version,
"description":
"Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.",
Expand Down
Loading

0 comments on commit cdec278

Please sign in to comment.