Skip to content

Commit

Permalink
chore: Update deno and dependencies
Browse files Browse the repository at this point in the history
refactor: Refactor tests and all modules
  • Loading branch information
motss committed Apr 18, 2020
1 parent b7521eb commit 5c7f19e
Show file tree
Hide file tree
Showing 25 changed files with 154 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-18.04, windows-2019]
target: [0.37]
target: [0.41]
timeout-minutes: 120

steps:
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Test
if: "env.CI_SKIP == 'false'"
run: |
deno run ./test.ts --reload
deno test --reload
- name: Benchmark
if: "env.CI_SKIP == 'false' && success()"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

## Pre-requisite

- [deno] >= 0.37.1
- [deno] >= 0.41.0

## Available modules

- [deep_clone] - Simple and fast deep cloning
- [delay_until] - A typical delay function but Promise based
- [jsmodern] - An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.
- [lit_ntml] - Expressive HTML Templates
- [normalize_diacritics] - Remove accents/ diacritics in string
- [polling_observer] - A new way of running polling function with observer pattern
- [delay_until] - A typical delay function but Promise based
- [jsmodern] - An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.

## Node.js equivalent

Expand Down
2 changes: 1 addition & 1 deletion bench.mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://cdn.jsdelivr.net/gh/denoland/deno@0.21.0/std/testing/bench.ts";
export * from "https://cdn.jsdelivr.net/gh/denoland/deno@0.41.0/std/testing/bench.ts";
2 changes: 1 addition & 1 deletion deep_clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

```ts
/** Import from GH via `denopkg` */
import { deepClone } from "https://cdn.jsdelivr.net/motss/deno_mod@v0.9.0/deep_clone/mod.ts";
import { deepClone } from "https://cdn.jsdelivr.net/gh/motss/deno_mod@v0.9.0/deep_clone/mod.ts";

(async () => {
const simpleObject = {
Expand Down
2 changes: 0 additions & 2 deletions deep_clone/mod.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions deep_clone/mod.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @deno-types="https://cdn.jsdelivr.net/npm/nodemod@latest/dist/deep-clone/index.d.ts"
export * from "https://cdn.jsdelivr.net/npm/nodemod@latest/dist/deep-clone/index.js";
// @deno-types="https://cdn.jsdelivr.net/npm/nodemod@2.6.1/dist/deep-clone/index.d.ts"
export * from "https://cdn.jsdelivr.net/npm/nodemod@2.6.1/dist/deep-clone/index.js";
2 changes: 1 addition & 1 deletion delay_until/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

```ts
/** Import from GH via `denopkg` */
import { delayUntil } from "https://cdn.jsdelivr.net/motss/deno_mod@v0.9.0/delay_until/mod.ts";
import { delayUntil } from "https://cdn.jsdelivr.net/gh/motss/deno_mod@v0.9.0/delay_until/mod.ts";

(async () => {
await delayUntil(3e3);
Expand Down
1 change: 0 additions & 1 deletion delay_until/mod.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion delay_until/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://cdn.jsdelivr.net/gh/motss/nodemod@latest/src/delay-until/index.ts";
export * from "https://cdn.jsdelivr.net/gh/motss/nodemod@2.6.1/src/delay-until/index.ts";
16 changes: 0 additions & 16 deletions jsmodern/mod.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions lit_ntml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#### html()

```ts
import { html } from "https://cdn.jsdelivr.net/motss/deno_mod@v0.9.0/lit_ntml/mod.ts";
import { html } from "https://cdn.jsdelivr.net/gh/motss/deno_mod@v0.9.0/lit_ntml/mod.ts";

const peopleList = ["Cash Black", "Vict Fisherman"];
const syncTask = () => `<h1>Hello, World!</h1>`;
Expand All @@ -40,7 +40,7 @@ await html`${syncTask}${asyncLiteral}${asyncListTask}`; /** <!DOCTYPE html><html
#### htmlFragment()

```ts
import { htmlFragment as html } from "https://cdn.jsdelivr.net/motss/deno_mod@v0.9.0/lit_ntml/mod.ts";
import { htmlFragment as html } from "https://cdn.jsdelivr.net/gh/motss/deno_mod@v0.9.0/lit_ntml/mod.ts";

const syncTask = () => `<h1>Hello, World!</h1>`;
const externalStyleLiteral = `<style>body { margin: 0; padding: 0; box-sizing: border-box; }</style>`;
Expand Down
53 changes: 53 additions & 0 deletions lit_ntml/html_fragment_sync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { assertStrictEq, prepareTest } from "../test.mod.ts";

import { helloWorld, peopleList } from "./CONSTANTS.ts";
import { htmlFragmentSync as html } from "./mod.ts";

function willRender() {
assertStrictEq(
html`${helloWorld}`,
`<h1>Hello, World!</h1>`
);
}

function willRenderWithSyncTasks() {
const syncTask = () => helloWorld;
const syncLiteral = "John Doe";

assertStrictEq(
html`<section>${syncTask}<h2>${syncLiteral}</h2></section>`,
// tslint:disable-next-line: max-line-length
`<section><h1>Hello, World!</h1><h2>John Doe</h2></section>`
);
}

function willRenderAListOfSyncTasks() {
assertStrictEq(
html`${helloWorld}<ul>${peopleList.map(n => `<li>${n}</li>`)}</ul>`,
// tslint:disable-next-line: max-line-length
`<h1>Hello, World!</h1><ul><li>John Doe</li><li>Michael CEO</li><li>Vict Fisherman</li><li>Cash Black</li></ul>`
);
}

function willRenderExternalStyle() {
// tslint:disable-next-line: max-line-length
const asyncExternalStyleTask = () =>
html`body { margin: 0; padding: 0; box-sizing: border-box; }`;

assertStrictEq(
html`<style>${asyncExternalStyleTask}</style>${helloWorld}`,
// tslint:disable-next-line: max-line-length
`<style>body { margin: 0; padding: 0; box-sizing: border-box; }</style><h1>Hello, World!</h1>`
);
}

prepareTest(
[
willRender,
willRenderAListOfSyncTasks,
willRenderExternalStyle,
willRenderWithSyncTasks
],
"lit_ntml",
"htmlFragmentSync"
);
41 changes: 41 additions & 0 deletions lit_ntml/html_sync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { assertStrictEq, prepareTest } from "../test.mod.ts";

import { helloWorld, peopleList } from "./CONSTANTS.ts";
import { htmlSync as html } from "./mod.ts";

function willRender() {
assertStrictEq(
html`${helloWorld}`,
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1></body></html>`
);
}

function willRenderWithSyncTasks() {
const syncTask = () => helloWorld;
const syncLiteral = "John Doe";

assertStrictEq(
html`<section>${syncTask}<h2>${syncLiteral}</h2></section>`,
// tslint:disable-next-line: max-line-length
`<!DOCTYPE html><html><head></head><body><section><h1>Hello, World!</h1><h2>John Doe</h2></section></body></html>`
);
}


function willRenderAListOfSyncTasks() {
assertStrictEq(
html`${helloWorld}<ul>${peopleList.map(n => `<li>${n}</li>`)}</ul>`,
// tslint:disable-next-line: max-line-length
`<!DOCTYPE html><html><head></head><body><h1>Hello, World!</h1><ul><li>John Doe</li><li>Michael CEO</li><li>Vict Fisherman</li><li>Cash Black</li></ul></body></html>`
);
}

prepareTest(
[
willRender,
willRenderAListOfSyncTasks,
willRenderWithSyncTasks
],
"lit_ntml",
"htmlSync"
);
35 changes: 34 additions & 1 deletion lit_ntml/mod.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { bench, BenchmarkTimer } from "../bench.mod.ts";

import { html, htmlFragment } from "./mod.ts";
import {
html,
htmlFragment,
htmlFragmentSync,
htmlSync
} from "./mod.ts";

const runs = 3;
const iter = 1e3;
Expand Down Expand Up @@ -32,3 +37,31 @@ bench({
b.stop();
}
});

bench({
runs,
name: `runs${runs}ForHtmlFragmentSyncX${iter}s`,
func(b: BenchmarkTimer) {
b.start();
for (let i = 0; i < iter; i += 1) {
htmlFragmentSync`<h1 class="main-title--${Math.random()
.toString(16)
.slice(-7)}">Hello, World</h1>`;
}
b.stop();
}
});

bench({
runs,
name: `runs${runs}ForHtmlSyncX${iter}s`,
func(b: BenchmarkTimer) {
b.start();
for (let i = 0; i < iter; i += 1) {
htmlSync`<h1 class="main-title--${Math.random()
.toString(16)
.slice(-7)}">Hello, World</h1>`;
}
b.stop();
}
});
3 changes: 0 additions & 3 deletions lit_ntml/mod.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions lit_ntml/mod.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @deno-types="https://cdn.jsdelivr.net/npm/nodemod@2.4.1/dist/lit-ntml/index.d.ts"
export * from "https://cdn.jsdelivr.net/npm/nodemod@2.4.1/dist/lit-ntml/index.min.js";
// @deno-types="https://cdn.jsdelivr.net/npm/lit-ntml@2.16.1/dist/lit-ntml.d.ts"
export * from "https://cdn.jsdelivr.net/npm/lit-ntml@2.16.1/dist/lit-ntml.min.js";
2 changes: 1 addition & 1 deletion normalize_diacritics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

```ts
/** Import from GH via `denopkg` */
import { normalize } from "https://cdn.jsdelivr.net/motss/deno_mod@v0.9.0/normalize_diacritics/mod.ts";
import { normalize } from "https://cdn.jsdelivr.net/gh/motss/deno_mod@v0.9.0/normalize_diacritics/mod.ts";

(async () => {
const str = "söme stüff with áccènts";
Expand Down
2 changes: 0 additions & 2 deletions normalize_diacritics/mod.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion normalize_diacritics/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://cdn.jsdelivr.net/gh/motss/normalize-diacritics@latest/src/normalize-diacritics.ts";
export * from "https://cdn.jsdelivr.net/gh/motss/normalize-diacritics@2.11.1/src/normalize-diacritics.ts";
2 changes: 1 addition & 1 deletion polling_observer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface DataType {
items: Record<string, any>[];
}

import { PollingObserver } from "https://cdn.jsdelivr.net/motss/deno_mod@v0.9.0/polling_observer/mod.ts";
import { PollingObserver } from "https://cdn.jsdelivr.net/gh/motss/deno_mod@v0.9.0/polling_observer/mod.ts";

const obs = new PollingObserver((data /** list, observer */) => {
const { status, items } = data || {};
Expand Down
2 changes: 0 additions & 2 deletions polling_observer/mod.test.ts

This file was deleted.

8 changes: 4 additions & 4 deletions polling_observer/mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @deno-types="https://cdn.jsdelivr.net/npm/nodemod@latest/dist/polling-observer/index.d.ts"
export * from "https://cdn.jsdelivr.net/npm/nodemod@latest/dist/polling-observer/index.js";
// @deno-types="https://cdn.jsdelivr.net/npm/nodemod@2.6.1/dist/polling-observer/index.d.ts"
export * from "https://cdn.jsdelivr.net/npm/nodemod@2.6.1/dist/polling-observer/index.js";

// @deno-types="https://cdn.jsdelivr.net/npm/nodemod@latest/dist/polling-observer/polling-measure.d.ts"
export * from "https://cdn.jsdelivr.net/npm/nodemod@latest/dist/polling-observer/polling-measure.js";
// @deno-types="https://cdn.jsdelivr.net/npm/nodemod@2.6.1/dist/polling-observer/polling-measure.d.ts"
export * from "https://cdn.jsdelivr.net/npm/nodemod@2.6.1/dist/polling-observer/polling-measure.js";
2 changes: 1 addition & 1 deletion run_test.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deno run ./test.ts --reload
deno test --reload
8 changes: 3 additions & 5 deletions test.mod.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { test as testFn } from "https://cdn.jsdelivr.net/gh/denoland/deno@0.21.0/std/testing/mod.ts";
import {
cyan,
yellow
} from "https://cdn.jsdelivr.net/gh/denoland/deno@0.21.0/std/fmt/colors.ts";
} from "https://cdn.jsdelivr.net/gh/denoland/deno@0.41.0/std/fmt/colors.ts";

export * from "https://cdn.jsdelivr.net/gh/denoland/deno@0.21.0/std/testing/mod.ts";
export * from "https://cdn.jsdelivr.net/gh/denoland/deno@0.21.0/std/testing/asserts.ts";
export * from "https://cdn.jsdelivr.net/gh/denoland/deno@0.41.0/std/testing/asserts.ts";

export function prepareTest(
tests: (() => any)[],
name: string,
prefix: string = ""
) {
return tests.map(n =>
testFn({
Deno.test({
name: `${cyan(name)} ${prefix && yellow(prefix) + " "}${n.name}`,
fn: n
})
Expand Down
14 changes: 0 additions & 14 deletions test.ts

This file was deleted.

0 comments on commit 5c7f19e

Please sign in to comment.