From 349c5b928726d8f808107ce4d0c0abfd1d15e937 Mon Sep 17 00:00:00 2001 From: Trygve Lie <173003+trygve-lie@users.noreply.github.com> Date: Tue, 27 Apr 2021 08:50:16 +0200 Subject: [PATCH] feat: Convert to ESM (#119) * feat: Convert to ESM BREAKING CHANGE: Convert from CommonJS to ESM * feat: convert to ESM * fix: Remove outcommented code * ci: Add build step for backward compat to CJS * ci: Ignore linting dist directory Co-authored-by: Trygve Lie --- .eslintignore | 1 + .eslintrc | 16 +++- .github/workflows/publish.yml | 4 +- .github/workflows/test.yml | 2 +- .gitignore | 1 + benchmark/benchmark.js | 2 +- dist/package.json | 3 + lib/asset-css.js | 10 +- lib/asset-js.js | 10 +- lib/html-document.js | 8 +- lib/html-utils.js | 23 ++--- lib/http-incoming.js | 10 +- lib/main.js | 48 +++++----- lib/utils.js | 44 +++------ package.json | 25 +++-- rollup.config.js | 16 ++++ .../html-document.js.test.cjs} | 0 tests/asset-css.js | 82 ++++++++-------- tests/asset-js.js | 94 +++++++++---------- tests/html-document.js | 7 +- tests/html-utils.js | 42 +++++---- tests/http-incoming.js | 18 ++-- tests/utils.js | 46 +++++---- 23 files changed, 253 insertions(+), 259 deletions(-) create mode 100644 dist/package.json create mode 100644 rollup.config.js rename tap-snapshots/{tests-html-document.js-TAP.test.js => tests/html-document.js.test.cjs} (100%) diff --git a/.eslintignore b/.eslintignore index 404abb2..d64c4ca 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ coverage/ +dist/ diff --git a/.eslintrc b/.eslintrc index 0cbba42..5b2cd9e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,9 +6,15 @@ "ecmaVersion": 11, "sourceType": "module" }, - "rules": { - "lines-between-class-members": [0], - "class-methods-use-this": [0], - "strict": [0, "global"] - } + "rules": { + "import/prefer-default-export": "off", + "class-methods-use-this": [0], + "lines-between-class-members": [0], + "import/extensions": ["error", { + "js": "ignorePackages" + } + ] + } } + + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a846464..d58d1b2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - name: npm install run: | npm install @@ -38,7 +38,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - name: npm install run: | npm install diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4e7b22e..cfd4623 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - node-version: [12.x, 14.x] + node-version: [12.x, 14.x, 16.x] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} diff --git a/.gitignore b/.gitignore index fd1f749..2efc68f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ coverage/ node_modules/ *.log .vscode +dist diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 5163397..e248fed 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -1,4 +1,4 @@ -'use strict'; + /* eslint no-unused-vars: "off", import/no-extraneous-dependencies: "off", no-console: "off" */ diff --git a/dist/package.json b/dist/package.json new file mode 100644 index 0000000..6a0d2ef --- /dev/null +++ b/dist/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} \ No newline at end of file diff --git a/lib/asset-css.js b/lib/asset-css.js index d40a82a..d7b6861 100644 --- a/lib/asset-css.js +++ b/lib/asset-css.js @@ -1,7 +1,5 @@ -'use strict'; - -const { uriIsRelative, pathnameBuilder } = require('./utils'); -const { buildLinkElement, buildReactLinkAttributes } = require('./html-utils'); +import { uriIsRelative, pathnameBuilder } from './utils.js'; +import { buildLinkElement, buildReactLinkAttributes } from './html-utils.js'; const inspect = Symbol.for('nodejs.util.inspect.custom'); @@ -14,7 +12,7 @@ const toUndefined = value => { return value; }; -const PodiumAssetCss = class PodiumAssetCss { +export default class PodiumAssetCss { #crossorigin; #pathname; #disabled; @@ -180,5 +178,3 @@ const PodiumAssetCss = class PodiumAssetCss { return 'PodiumAssetCss'; } }; - -module.exports = PodiumAssetCss; diff --git a/lib/asset-js.js b/lib/asset-js.js index fec7bf7..f41a930 100644 --- a/lib/asset-js.js +++ b/lib/asset-js.js @@ -1,7 +1,7 @@ -'use strict'; -const { uriIsRelative, pathnameBuilder } = require('./utils'); -const { buildScriptElement, buildReactScriptAttributes } = require('./html-utils'); + +import { uriIsRelative, pathnameBuilder } from './utils.js'; +import { buildScriptElement, buildReactScriptAttributes } from './html-utils.js'; const inspect = Symbol.for('nodejs.util.inspect.custom'); @@ -15,7 +15,7 @@ const toUndefined = (value) => { return value; }; -const PodiumAssetJs = class PodiumAssetJs { +export default class PodiumAssetJs { #referrerpolicy; #crossorigin; #integrity; @@ -181,5 +181,3 @@ const PodiumAssetJs = class PodiumAssetJs { return 'PodiumAssetJs'; } }; - -module.exports = PodiumAssetJs; diff --git a/lib/html-document.js b/lib/html-document.js index c30271c..36ac642 100644 --- a/lib/html-document.js +++ b/lib/html-document.js @@ -1,8 +1,6 @@ -'use strict'; +import * as utils from './html-utils.js'; -const utils = require('./html-utils'); - -const document = (incoming = {}, body = '', head = '') => { +export const document = (incoming = {}, body = '', head = '') => { let scripts = incoming.js; let styles = incoming.css; @@ -26,5 +24,3 @@ const document = (incoming = {}, body = '', head = '') => { `; }; - -module.exports = document; diff --git a/lib/html-utils.js b/lib/html-utils.js index 0645697..e2fc06d 100644 --- a/lib/html-utils.js +++ b/lib/html-utils.js @@ -1,8 +1,6 @@ /* eslint-disable no-restricted-syntax */ -'use strict'; - -const notEmpty = (value) => { +export const notEmpty = (value) => { if (value === false) return value; if (value === undefined) return false; if (value === null) return false; @@ -10,7 +8,7 @@ const notEmpty = (value) => { return false; }; -const buildScriptAttributes = (obj) => { +export const buildScriptAttributes = (obj) => { const args = []; args.push({ key: 'src', value: obj.value }); @@ -52,7 +50,7 @@ const buildScriptAttributes = (obj) => { return args; }; -const buildReactScriptAttributes = (obj) => { +export const buildReactScriptAttributes = (obj) => { const attrs = {}; for (const { key, value } of buildScriptAttributes(obj)) { if (key === 'crossorigin') attrs.crossOrigin = value || ''; @@ -64,7 +62,7 @@ const buildReactScriptAttributes = (obj) => { return attrs; } -const buildScriptElement = (obj) => { +export const buildScriptElement = (obj) => { const attrs = buildScriptAttributes(obj).map(({key, value}) => { if (!value && value !== '') return key; return `${key}="${value}"`; @@ -72,7 +70,7 @@ const buildScriptElement = (obj) => { return ``; }; -const buildLinkAttributes = (obj) => { +export const buildLinkAttributes = (obj) => { const args = []; args.push({ key: 'href', value: obj.value }); @@ -112,7 +110,7 @@ const buildLinkAttributes = (obj) => { return args; }; -const buildReactLinkAttributes = (obj) => { +export const buildReactLinkAttributes = (obj) => { const attrs = {}; for (const { key, value } of buildLinkAttributes(obj)) { if (key === 'crossorigin') attrs.crossOrigin = value || ''; @@ -123,17 +121,10 @@ const buildReactLinkAttributes = (obj) => { return attrs; } -const buildLinkElement = (obj) => { +export const buildLinkElement = (obj) => { const attrs = buildLinkAttributes(obj).map(({key, value}) => { if (!value && value !== '') return key; return `${key}="${value}"`; }) return ``; }; - -module.exports.buildLinkAttributes = buildLinkAttributes; -module.exports.buildReactLinkAttributes = buildReactLinkAttributes; -module.exports.buildScriptAttributes = buildScriptAttributes; -module.exports.buildReactScriptAttributes = buildReactScriptAttributes; -module.exports.buildScriptElement = buildScriptElement; -module.exports.buildLinkElement = buildLinkElement; diff --git a/lib/http-incoming.js b/lib/http-incoming.js index 1a44927..0f6f709 100644 --- a/lib/http-incoming.js +++ b/lib/http-incoming.js @@ -1,7 +1,5 @@ -'use strict'; - -const originalUrl = require('original-url'); -const { URL } = require('url'); +import originalUrl from 'original-url'; +import { URL } from 'url'; const inspect = Symbol.for('nodejs.util.inspect.custom'); @@ -14,7 +12,7 @@ const urlFromRequest = request => { } }; -const PodiumHttpIncoming = class PodiumHttpIncoming { +export default class PodiumHttpIncoming { #development; #response; #request; @@ -192,5 +190,3 @@ const PodiumHttpIncoming = class PodiumHttpIncoming { return 'PodiumHttpIncoming'; } }; - -module.exports = PodiumHttpIncoming; diff --git a/lib/main.js b/lib/main.js index f2e414c..9b8711c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,26 +1,24 @@ -'use strict'; +import * as Incoming from "./http-incoming.js"; +import { document } from "./html-document.js"; +import * as Css from "./asset-css.js"; +import * as Js from "./asset-js.js"; +import * as utils from "./utils.js" +import * as html from "./html-utils.js" -const HttpIncoming = require('./http-incoming'); -const document = require('./html-document'); -const AssetCss = require('./asset-css'); -const AssetJs = require('./asset-js'); -const utils = require('./utils'); -const html = require('./html-utils'); - -module.exports.isString = utils.isString; -module.exports.isFunction = utils.isFunction; -module.exports.uriBuilder = utils.uriBuilder; -module.exports.uriIsRelative = utils.uriIsRelative; -module.exports.pathnameBuilder = utils.pathnameBuilder; -module.exports.uriRelativeToAbsolute = utils.uriRelativeToAbsolute; -module.exports.setAtLocalsPodium = utils.setAtLocalsPodium; -module.exports.getFromLocalsPodium = utils.getFromLocalsPodium; -module.exports.duplicateOnLocalsPodium = utils.duplicateOnLocalsPodium; -module.exports.serializeContext = utils.serializeContext; -module.exports.deserializeContext = utils.deserializeContext; -module.exports.buildScriptElement = html.buildScriptElement; -module.exports.buildLinkElement = html.buildLinkElement; -module.exports.HttpIncoming = HttpIncoming; -module.exports.template = document; -module.exports.AssetCss = AssetCss; -module.exports.AssetJs = AssetJs; +export const {isString} = utils; +export const {isFunction} = utils; +export const {uriBuilder} = utils; +export const {uriIsRelative} = utils; +export const {pathnameBuilder} = utils; +export const {uriRelativeToAbsolute} = utils; +export const {setAtLocalsPodium} = utils; +export const {getFromLocalsPodium} = utils; +export const {duplicateOnLocalsPodium} = utils; +export const {serializeContext} = utils; +export const {deserializeContext} = utils; +export const {buildScriptElement} = html; +export const {buildLinkElement} = html; +export const HttpIncoming = Incoming; +export const template = document; +export const AssetCss = Css; +export const AssetJs = Js; diff --git a/lib/utils.js b/lib/utils.js index 7f89e12..b4e3a21 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,7 +1,5 @@ -'use strict'; - -const camelcase = require('camelcase'); -const { URL } = require('url'); +import camelcase from 'camelcase'; +import { URL } from 'url'; /** * Checks if a value is a string @@ -10,7 +8,7 @@ const { URL } = require('url'); * * @returns {Boolean} */ -const isString = str => typeof str === 'string'; +export const isString = str => typeof str === 'string'; /** * Checks if a value is a function @@ -19,7 +17,7 @@ const isString = str => typeof str === 'string'; * * @returns {Boolean} */ -const isFunction = fn => { +export const isFunction = fn => { const type = {}.toString.call(fn); return type === '[object Function]' || type === '[object AsyncFunction]'; }; @@ -35,7 +33,7 @@ const isFunction = fn => { * @returns {String} an pathname */ -const pathnameBuilder = (...args) => { +export const pathnameBuilder = (...args) => { const separator = '/'; let prefixCheck = true; let prefix = ''; @@ -81,7 +79,7 @@ const pathnameBuilder = (...args) => { * @returns {String} an absolute URI */ -const uriBuilder = (input = '', base = '', extra = '') => { +export const uriBuilder = (input = '', base = '', extra = '') => { const uriObj = new URL(base); const basePath = uriObj.pathname .split('/') @@ -98,7 +96,7 @@ const uriBuilder = (input = '', base = '', extra = '') => { * @returns {Boolean} */ -const uriIsRelative = uri => uri.substr(0, 4) !== 'http'; +export const uriIsRelative = uri => uri.substr(0, 4) !== 'http'; /** * Check if a URI is absolute or relative and if relative compose an @@ -111,9 +109,9 @@ const uriIsRelative = uri => uri.substr(0, 4) !== 'http'; * @returns {String} an absolute URI */ -const uriRelativeToAbsolute = (input = '', base = '', extra = '') => { - if (this.uriIsRelative(input)) { - return this.uriBuilder(input, base, extra); +export const uriRelativeToAbsolute = (input = '', base = '', extra = '') => { + if (uriIsRelative(input)) { + return uriBuilder(input, base, extra); } return input; }; @@ -132,7 +130,7 @@ const uriRelativeToAbsolute = (input = '', base = '', extra = '') => { * @returns {Object} The http response object */ -const setAtLocalsPodium = (response = {}, property, value) => { +export const setAtLocalsPodium = (response = {}, property, value) => { if (!response.locals) { response.locals = {}; } @@ -158,7 +156,7 @@ const setAtLocalsPodium = (response = {}, property, value) => { * @returns {Object} The property, or `null` if it does not exist */ -const getFromLocalsPodium = (response = {}, property) => { +export const getFromLocalsPodium = (response = {}, property) => { if (!response.locals) { return null; } @@ -185,7 +183,7 @@ const getFromLocalsPodium = (response = {}, property) => { * @returns {Object} The http response object */ -const duplicateOnLocalsPodium = (response = {}, fromProperty, toProperty) => +export const duplicateOnLocalsPodium = (response = {}, fromProperty, toProperty) => setAtLocalsPodium( response, toProperty, @@ -202,7 +200,7 @@ const duplicateOnLocalsPodium = (response = {}, fromProperty, toProperty) => * @returns {Object} A http header object */ -const serializeContext = (headers = {}, context = {}, arg = '') => { +export const serializeContext = (headers = {}, context = {}, arg = '') => { const localHeaders = headers; Object.keys(context).forEach(key => { if (isString(context[key])) { @@ -225,7 +223,7 @@ const serializeContext = (headers = {}, context = {}, arg = '') => { * @returns {Object} A object containing context properties and values */ -const deserializeContext = (headers = {}, prefix = 'podium') => { +export const deserializeContext = (headers = {}, prefix = 'podium') => { const context = {}; Object.keys(headers).forEach(key => { if (key.startsWith(prefix)) { @@ -235,15 +233,3 @@ const deserializeContext = (headers = {}, prefix = 'podium') => { }); return context; }; - -module.exports.isString = isString; -module.exports.isFunction = isFunction; -module.exports.uriBuilder = uriBuilder; -module.exports.uriIsRelative = uriIsRelative; -module.exports.pathnameBuilder = pathnameBuilder; -module.exports.uriRelativeToAbsolute = uriRelativeToAbsolute; -module.exports.setAtLocalsPodium = setAtLocalsPodium; -module.exports.getFromLocalsPodium = getFromLocalsPodium; -module.exports.duplicateOnLocalsPodium = duplicateOnLocalsPodium; -module.exports.serializeContext = serializeContext; -module.exports.deserializeContext = deserializeContext; diff --git a/package.json b/package.json index 03e53c3..b2842f6 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "@podium/utils", "version": "5.0.0-next.3", "description": "Common generic utility methods shared by @podium modules.", + "type": "module", "license": "MIT", "keywords": [ "micro services", @@ -23,16 +24,23 @@ "index.d.ts", "README.md", "LICENSE", + "dist", "lib" ], - "main": "./lib/main.js", + "main": "./dist/main.js", + "exports": { + "require": "./dist/validate.js", + "import": "./lib/main.js" + }, "types": "index.d.ts", "scripts": { "lint": "eslint .", "lint:fix": "eslint --fix .", - "test": "tap --no-esm tests/*.js", - "test:snapshots:update": "tap --no-esm tests/*.js --snapshot", - "bench": "node benchmark/benchmark.js" + "test": "tap --no-check-coverage", + "test:snapshots:update": "tap --snapshot", + "bench": "node benchmark/benchmark.js", + "prepare": "npm run -s build", + "build": "rollup -c" }, "devDependencies": { "@semantic-release/changelog": "5.0.1", @@ -48,13 +56,14 @@ "eslint-config-prettier": "8.3.0", "eslint-plugin-import": "2.22.1", "eslint-plugin-prettier": "3.4.0", + "rollup": "2.45.2", "babel-eslint": "10.1.0", - "jest": "26.6.3", + "tap": "15.0.5", "prettier": "2.2.1" }, "dependencies": { - "@podium/schemas": "4.1.15", - "original-url": "1.2.3", - "camelcase": "6.2.0" + "@podium/schemas": "5.0.0-next.4", + "camelcase": "6.2.0", + "original-url": "1.2.3" } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..189df58 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,16 @@ +export default { + input: 'lib/main.js', + external: [ + 'original-url', + 'camelcase', + 'url', + ], + output: [ + { + exports: 'auto', + format: 'cjs', + dir: 'dist/', + preserveModules: true, + } + ], +}; diff --git a/tap-snapshots/tests-html-document.js-TAP.test.js b/tap-snapshots/tests/html-document.js.test.cjs similarity index 100% rename from tap-snapshots/tests-html-document.js-TAP.test.js rename to tap-snapshots/tests/html-document.js.test.cjs diff --git a/tests/asset-css.js b/tests/asset-css.js index 0b14eea..6550a12 100644 --- a/tests/asset-css.js +++ b/tests/asset-css.js @@ -1,11 +1,9 @@ -'use strict'; - -const { validate } = require('@podium/schemas'); -const tap = require('tap'); -const Css = require('../lib/asset-css'); +import tap from 'tap'; +import * as schema from '@podium/schemas'; +import AssetCss from '../lib/asset-css.js'; tap.test('Css() - object tag - should be PodiumAssetCss', (t) => { - const obj = new Css({ value: '/foo' }); + const obj = new AssetCss({ value: '/foo' }); t.equal(Object.prototype.toString.call(obj), '[object PodiumAssetCss]'); t.end(); }); @@ -13,15 +11,15 @@ tap.test('Css() - object tag - should be PodiumAssetCss', (t) => { tap.test('Css() - no value given to "value" argument', (t) => { t.plan(1); t.throws(() => { - const obj = new Css(); // eslint-disable-line no-unused-vars + const obj = new AssetCss(); // eslint-disable-line no-unused-vars }, /Value for argument variable "value", "undefined", is not valid/, 'Should throw'); t.end(); }); tap.test('Css() - no arguments given - should construct object with default values', (t) => { - const obj = new Css({ value: '/foo' }); + const obj = new AssetCss({ value: '/foo' }); t.equal(obj.crossorigin, undefined); - t.false(obj.disabled); + t.notOk(obj.disabled); t.equal(obj.hreflang, ''); t.equal(obj.value, '/foo'); t.equal(obj.title, ''); @@ -34,7 +32,7 @@ tap.test('Css() - no arguments given - should construct object with default valu }); tap.test('Css() - no arguments given - should construct JSON with default values', (t) => { - const obj = new Css({ value: '/foo' }); + const obj = new AssetCss({ value: '/foo' }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -45,28 +43,28 @@ tap.test('Css() - no arguments given - should construct JSON with default values }); tap.test('Css() - pathname is given - prefix is unset - should NOT append pathname to "value"', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar' }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar' }); t.equal(obj.value, '/foo'); t.equal(obj.href, '/foo'); t.end(); }); tap.test('Css() - pathname is given - prefix is false - should NOT append pathname to "value"', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar', prefix: false }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar', prefix: false }); t.equal(obj.value, '/foo'); t.equal(obj.href, '/foo'); t.end(); }); tap.test('Css() - pathname is given - prefix is true - should append pathname to "value"', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar', prefix: true }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar', prefix: true }); t.equal(obj.value, '/bar/foo'); t.equal(obj.href, '/bar/foo'); t.end(); }); tap.test('Css() - pathname is given - prefix is unset - should NOT append pathname to "value" for toJSON()', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar' }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar' }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -77,7 +75,7 @@ tap.test('Css() - pathname is given - prefix is unset - should NOT append pathna }); tap.test('Css() - pathname is given - prefix is false - should NOT append pathname to "value" for toJSON()', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar', prefix: false }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar', prefix: false }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -88,7 +86,7 @@ tap.test('Css() - pathname is given - prefix is false - should NOT append pathna }); tap.test('Css() - pathname is given - prefix is true - should NOT append pathname to "value" for toJSON()', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar', prefix: true }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar', prefix: true }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -99,26 +97,26 @@ tap.test('Css() - pathname is given - prefix is true - should NOT append pathnam }); tap.test('Css() - pathname is given - prefix is unset - should NOT append pathname to "href" for toHTML()', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar' }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar' }); t.equal(obj.toHTML(), ''); t.end(); }); tap.test('Css() - pathname is given - prefix is false - should NOT append pathname to "href" for toHTML()', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar', prefix: false }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar', prefix: false }); t.equal(obj.value, '/foo'); t.equal(obj.toHTML(), ''); t.end(); }); tap.test('Css() - pathname is given - prefix is true - should append pathname to "href" for toHTML()', (t) => { - const obj = new Css({ value: '/foo', pathname: '/bar', prefix: true }); + const obj = new AssetCss({ value: '/foo', pathname: '/bar', prefix: true }); t.equal(obj.toHTML(), ''); t.end(); }); tap.test('Css() - value if absoulte - pathname is given - prefix is true - should NOT append pathname to "value"', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: 'http://somewhere.else.com/foo', pathname: '/bar', prefix: true, @@ -138,7 +136,7 @@ tap.test('Css() - value if absoulte - pathname is given - prefix is true - shoul }); tap.test('Css() - set "crossorigin" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); @@ -157,19 +155,19 @@ tap.test('Css() - set "crossorigin" - should construct object as expected', (t) rel: 'stylesheet', }); - const repl = new Css(json); + const repl = new AssetCss(json); t.equal(repl.crossorigin, 'bar'); t.end(); }); tap.test('Css() - set "disabled" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); obj.disabled = true; - t.true(obj.disabled); + t.ok(obj.disabled); t.equal(obj.toHTML(), '', ); @@ -182,13 +180,13 @@ tap.test('Css() - set "disabled" - should construct object as expected', (t) => rel: 'stylesheet', }); - const repl = new Css(json); - t.true(repl.disabled); + const repl = new AssetCss(json); + t.ok(repl.disabled); t.end(); }); tap.test('Css() - set "hreflang" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); @@ -207,13 +205,13 @@ tap.test('Css() - set "hreflang" - should construct object as expected', (t) => rel: 'stylesheet', }); - const repl = new Css(json); + const repl = new AssetCss(json); t.equal(repl.hreflang, 'bar'); t.end(); }); tap.test('Css() - set "title" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); @@ -232,13 +230,13 @@ tap.test('Css() - set "title" - should construct object as expected', (t) => { rel: 'stylesheet', }); - const repl = new Css(json); + const repl = new AssetCss(json); t.equal(repl.title, 'bar'); t.end(); }); tap.test('Css() - set "media" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); @@ -257,13 +255,13 @@ tap.test('Css() - set "media" - should construct object as expected', (t) => { rel: 'stylesheet', }); - const repl = new Css(json); + const repl = new AssetCss(json); t.equal(repl.media, 'bar'); t.end(); }); tap.test('Css() - set "type" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); @@ -281,13 +279,13 @@ tap.test('Css() - set "type" - should construct object as expected', (t) => { rel: 'stylesheet', }); - const repl = new Css(json); + const repl = new AssetCss(json); t.equal(repl.type, 'bar'); t.end(); }); tap.test('Css() - set "rel" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); @@ -305,13 +303,13 @@ tap.test('Css() - set "rel" - should construct object as expected', (t) => { rel: 'bar', }); - const repl = new Css(json); + const repl = new AssetCss(json); t.equal(repl.rel, 'bar'); t.end(); }); tap.test('Css() - set "as" - should construct object as expected', (t) => { - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); @@ -330,14 +328,14 @@ tap.test('Css() - set "as" - should construct object as expected', (t) => { rel: 'stylesheet', }); - const repl = new Css(json); + const repl = new AssetCss(json); t.equal(repl.as, 'bar'); t.end(); }); tap.test('Css() - set "value"', (t) => { t.plan(1); - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); t.throws(() => { @@ -348,7 +346,7 @@ tap.test('Css() - set "value"', (t) => { tap.test('Css() - set "href" - should throw', (t) => { t.plan(1); - const obj = new Css({ + const obj = new AssetCss({ value: '/foo', }); t.throws(() => { @@ -358,7 +356,7 @@ tap.test('Css() - set "href" - should throw', (t) => { }); tap.test('Css() - validate object against schema - should validate', (t) => { - const obj = new Css({ value: '/foo' }); - t.false(validate.css([obj]).error); + const obj = new AssetCss({ value: '/foo' }); + t.notOk(schema.css([obj]).error); t.end(); }); diff --git a/tests/asset-js.js b/tests/asset-js.js index d39a369..9cddb63 100644 --- a/tests/asset-js.js +++ b/tests/asset-js.js @@ -1,11 +1,9 @@ -'use strict'; - -const { validate } = require('@podium/schemas'); -const tap = require('tap'); -const Js = require('../lib/asset-js'); +import tap from 'tap'; +import * as schema from '@podium/schemas'; +import AssetJs from '../lib/asset-js.js'; tap.test('Js() - object tag - should be PodiumAssetJs', (t) => { - const obj = new Js({ value: '/foo' }); + const obj = new AssetJs({ value: '/foo' }); t.equal(Object.prototype.toString.call(obj), '[object PodiumAssetJs]', ); @@ -15,19 +13,19 @@ tap.test('Js() - object tag - should be PodiumAssetJs', (t) => { tap.test('Js() - no value given to "value" argument', (t) => { t.plan(1); t.throws(() => { - const obj = new Js(); // eslint-disable-line no-unused-vars + const obj = new AssetJs(); // eslint-disable-line no-unused-vars }, /Value for argument variable "value", "undefined", is not valid/, 'Should throw'); t.end(); }); tap.test('Js() - no arguments given - should construct object with default values', (t) => { - const obj = new Js({ value: '/foo' }); + const obj = new AssetJs({ value: '/foo' }); t.equal(obj.referrerpolicy, ''); t.equal(obj.crossorigin, undefined); t.equal(obj.integrity, ''); - t.false(obj.nomodule); - t.false(obj.async); - t.false(obj.defer); + t.notOk(obj.nomodule); + t.notOk(obj.async); + t.notOk(obj.defer); t.equal(obj.value, '/foo'); t.equal(obj.type, 'default'); t.equal(obj.src, '/foo'); @@ -36,7 +34,7 @@ tap.test('Js() - no arguments given - should construct object with default value }); tap.test('Js() - no arguments given - should construct JSON with default values', (t) => { - const obj = new Js({ value: '/foo' }); + const obj = new AssetJs({ value: '/foo' }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -46,28 +44,28 @@ tap.test('Js() - no arguments given - should construct JSON with default values' }); tap.test('Js() - pathname is given - prefix is unset - should NOT append pathname to "value"', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar' }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar' }); t.equal(obj.value, '/foo'); t.equal(obj.src, '/foo'); t.end(); }); tap.test('Js() - pathname is given - prefix is false - should NOT append pathname to "value"', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar', prefix: false }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar', prefix: false }); t.equal(obj.value, '/foo'); t.equal(obj.src, '/foo'); t.end(); }); tap.test('Js() - pathname is given - prefix is true - should append pathname to "value"', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar', prefix: true }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar', prefix: true }); t.equal(obj.value, '/bar/foo'); t.equal(obj.src, '/bar/foo'); t.end(); }); tap.test('Js() - pathname is given - prefix is unset - should NOT append pathname to "value" for toJSON()', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar' }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar' }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -77,7 +75,7 @@ tap.test('Js() - pathname is given - prefix is unset - should NOT append pathnam }); tap.test('Js() - pathname is given - prefix is false - should NOT append pathname to "value" for toJSON()', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar', prefix: false }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar', prefix: false }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -87,7 +85,7 @@ tap.test('Js() - pathname is given - prefix is false - should NOT append pathnam }); tap.test('Js() - pathname is given - prefix is true - should NOT append pathname to "value" for toJSON()', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar', prefix: true }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar', prefix: true }); const json = JSON.parse(JSON.stringify(obj)); t.same(json, { value: '/foo', @@ -97,26 +95,26 @@ tap.test('Js() - pathname is given - prefix is true - should NOT append pathname }); tap.test('Js() - pathname is given - prefix is unset - should NOT append pathname to "src" for toHTML()', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar' }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar' }); t.equal(obj.toHTML(), ''); t.end(); }); tap.test('Js() - pathname is given - prefix is false - should NOT append pathname to "src" for toHTML()', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar', prefix: false }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar', prefix: false }); t.equal(obj.value, '/foo'); t.equal(obj.toHTML(), ''); t.end(); }); tap.test('Js() - pathname is given - prefix is true - should append pathname to "src" for toHTML()', (t) => { - const obj = new Js({ value: '/foo', pathname: '/bar', prefix: true }); + const obj = new AssetJs({ value: '/foo', pathname: '/bar', prefix: true }); t.equal(obj.toHTML(), ''); t.end(); }); tap.test('Js() - value if absoulte - pathname is given - prefix is true - should NOT append pathname to "value"', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: 'http://somewhere.else.com/foo', pathname: '/bar', prefix: true, @@ -137,7 +135,7 @@ tap.test('Js() - value if absoulte - pathname is given - prefix is true - should }); tap.test('Js() - set "referrerpolicy" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); @@ -155,13 +153,13 @@ tap.test('Js() - set "referrerpolicy" - should construct object as t.equaled', ( type: 'default', }); - const repl = new Js(json); + const repl = new AssetJs(json); t.equal(repl.referrerpolicy, 'bar'); t.end(); }); tap.test('Js() - set "crossorigin" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); @@ -179,13 +177,13 @@ tap.test('Js() - set "crossorigin" - should construct object as t.equaled', (t) type: 'default', }); - const repl = new Js(json); + const repl = new AssetJs(json); t.equal(repl.crossorigin, 'bar'); t.end(); }); tap.test('Js() - set "integrity" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); @@ -203,19 +201,19 @@ tap.test('Js() - set "integrity" - should construct object as t.equaled', (t) => type: 'default', }); - const repl = new Js(json); + const repl = new AssetJs(json); t.equal(repl.integrity, 'bar'); t.end(); }); tap.test('Js() - set "nomodule" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); obj.nomodule = true; - t.true(obj.nomodule); + t.ok(obj.nomodule); t.equal(obj.toHTML(), ''); const json = JSON.parse(JSON.stringify(obj)); @@ -225,19 +223,19 @@ tap.test('Js() - set "nomodule" - should construct object as t.equaled', (t) => type: 'default', }); - const repl = new Js(json); - t.true(repl.nomodule); + const repl = new AssetJs(json); + t.ok(repl.nomodule); t.end(); }); tap.test('Js() - set "async" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); obj.async = true; - t.true(obj.async); + t.ok(obj.async); t.equal(obj.toHTML(), ''); const json = JSON.parse(JSON.stringify(obj)); @@ -247,19 +245,19 @@ tap.test('Js() - set "async" - should construct object as t.equaled', (t) => { type: 'default', }); - const repl = new Js(json); - t.true(repl.async); + const repl = new AssetJs(json); + t.ok(repl.async); t.end(); }); tap.test('Js() - set "defer" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); obj.defer = true; - t.true(obj.defer); + t.ok(obj.defer); t.equal(obj.toHTML(), ''); const json = JSON.parse(JSON.stringify(obj)); @@ -269,13 +267,13 @@ tap.test('Js() - set "defer" - should construct object as t.equaled', (t) => { type: 'default', }); - const repl = new Js(json); - t.true(repl.defer); + const repl = new AssetJs(json); + t.ok(repl.defer); t.end(); }); tap.test('Js() - set "type" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); @@ -290,13 +288,13 @@ tap.test('Js() - set "type" - should construct object as t.equaled', (t) => { type: 'esm', }); - const repl = new Js(json); + const repl = new AssetJs(json); t.equal(repl.type, 'esm'); t.end(); }); tap.test('Js() - set "data" - should construct object as t.equaled', (t) => { - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); @@ -321,7 +319,7 @@ tap.test('Js() - set "data" - should construct object as t.equaled', (t) => { type: 'default', }); - const repl = new Js(json); + const repl = new AssetJs(json); t.same(repl.data, [{ key: 'foo', value: 'bar' @@ -331,7 +329,7 @@ tap.test('Js() - set "data" - should construct object as t.equaled', (t) => { tap.test('Js() - set "value"', (t) => { t.plan(1); - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); t.throws(() => { @@ -342,7 +340,7 @@ tap.test('Js() - set "value"', (t) => { tap.test('Js() - set "src"', (t) => { t.plan(1); - const obj = new Js({ + const obj = new AssetJs({ value: '/foo', }); t.throws(() => { @@ -352,7 +350,7 @@ tap.test('Js() - set "src"', (t) => { }); tap.test('Js() - validate object against schema - should validate', (t) => { - const obj = new Js({ value: '/foo' }); - t.false(validate.js([obj]).error); + const obj = new AssetJs({ value: '/foo' }); + t.notOk(schema.js([obj]).error); t.end(); }); diff --git a/tests/html-document.js b/tests/html-document.js index 72ce0ec..15568b9 100644 --- a/tests/html-document.js +++ b/tests/html-document.js @@ -1,8 +1,7 @@ -'use strict'; +import tap from 'tap'; +import HttpIncoming from '../lib/http-incoming.js'; +import { document } from '../lib/html-document.js'; -const tap = require('tap'); -const HttpIncoming = require('../lib/http-incoming'); -const document = require('../lib/html-document'); const SIMPLE_REQ = { headers: {}, diff --git a/tests/html-utils.js b/tests/html-utils.js index 19d1ca4..2624921 100644 --- a/tests/html-utils.js +++ b/tests/html-utils.js @@ -1,9 +1,8 @@ -'use strict'; +import tap from 'tap'; +import AssetCss from '../lib/asset-css.js'; +import AssetJs from '../lib/asset-js.js' +import * as utils from '../lib/html-utils.js' -const tap = require('tap'); -const AssetCss = require('../lib/asset-css'); -const AssetJs = require('../lib/asset-js'); -const utils = require('../lib/html-utils'); /** * .buildLinkElement() @@ -415,14 +414,15 @@ tap.test('.buildScriptElement() - crossorigin boolean false', (t) => { t.end(); }); -test('.buildScriptAttributes() - basic', () => { +tap.test('.buildScriptAttributes() - basic', (t) => { const obj = new AssetJs({ value: '/bar' }); - expect(utils.buildScriptAttributes(obj)).toEqual([ + t.same(utils.buildScriptAttributes(obj), [ { key: 'src', value: '/bar' } ]); + t.end(); }); -test('.buildScriptAttributes() - advanced', () => { +tap.test('.buildScriptAttributes() - advanced', (t) => { const obj = new AssetJs({ value: '/bar', crossorigin: true, @@ -431,7 +431,7 @@ test('.buildScriptAttributes() - advanced', () => { defer: true, type: 'module', }); - expect(utils.buildScriptAttributes(obj)).toEqual([ + t.same(utils.buildScriptAttributes(obj), [ { key: 'src', value: '/bar' }, { key: 'type', value: 'module' }, { key: 'crossorigin' }, @@ -439,18 +439,21 @@ test('.buildScriptAttributes() - advanced', () => { { key: 'async' }, { key: 'defer' }, ]); + t.end(); }); -test('.buildLinkAttributes() - basic', () => { +tap.test('.buildLinkAttributes() - basic', (t) => { const obj = new AssetCss({ value: '/bar' }); - expect(utils.buildLinkAttributes(obj)).toEqual([ + t.same(utils.buildLinkAttributes(obj), [ { key: 'href', value: '/bar' }, { key: 'type', value: 'text/css' }, { key: 'rel', value: 'stylesheet' }, ]); + t.end(); }); -test('.buildLinkAttributes() - advanced', () => { + +tap.test('.buildLinkAttributes() - advanced', (t) => { const obj = new AssetCss({ value: '/bar', disabled: true, @@ -461,9 +464,9 @@ test('.buildLinkAttributes() - advanced', () => { type: 'test5', rel: 'test6', }); - expect(utils.buildLinkAttributes(obj)).toEqual([ + t.same(utils.buildLinkAttributes(obj), [ { key: 'href', value: '/bar' }, - { key: 'disabled', value: undefined }, + { key: 'disabled' }, { key: 'hreflang', value: 'test1' }, { key: 'title', value: 'test2' }, { key: 'media', value: 'test3' }, @@ -471,9 +474,10 @@ test('.buildLinkAttributes() - advanced', () => { { key: 'type', value: 'test5' }, { key: 'rel', value: 'test6' }, ]); + t.end(); }); -test('.buildReactScriptAttributes()', () => { +tap.test('.buildReactScriptAttributes()', (t) => { const obj = new AssetJs({ value: '/bar', crossorigin: true, @@ -481,26 +485,28 @@ test('.buildReactScriptAttributes()', () => { defer: true, nomodule: true, }); - expect(utils.buildReactScriptAttributes(obj)).toEqual({ + t.same(utils.buildReactScriptAttributes(obj), { src: '/bar', crossOrigin: '', noModule: true, async: true, defer: true, }); + t.end(); }); -test('.buildReactLinkAttributes()', () => { +tap.test('.buildReactLinkAttributes()', (t) => { const obj = new AssetCss({ value: '/bar', crossorigin: true, disabled: true, }); - expect(utils.buildReactLinkAttributes(obj)).toEqual({ + t.same(utils.buildReactLinkAttributes(obj), { href: '/bar', crossOrigin: '', rel: 'stylesheet', disabled: true, type: 'text/css', }); + t.end(); }); diff --git a/tests/http-incoming.js b/tests/http-incoming.js index b864439..6fcbcc2 100644 --- a/tests/http-incoming.js +++ b/tests/http-incoming.js @@ -1,7 +1,5 @@ -'use strict'; - -const tap = require('tap'); -const HttpIncoming = require('../lib/http-incoming'); +import tap from 'tap'; +import HttpIncoming from '../lib/http-incoming.js'; const SIMPLE_REQ = {}; @@ -33,9 +31,9 @@ tap.test('PodiumHttpIncoming() - no arguments given - should construct object wi t.same(incoming.response, {}); t.same(incoming.url, {}); t.same(incoming.params, {}); - t.false(incoming.proxy); + t.notOk(incoming.proxy); t.same(incoming.context, {}); - t.false(incoming.development); + t.notOk(incoming.development); t.equal(incoming.name, ''); t.same(incoming.css, []); t.same(incoming.js, []); @@ -158,7 +156,7 @@ tap.test('PodiumHttpIncoming.url - set value - should set value', (t) => { tap.test('PodiumHttpIncoming.development - set value - should set value', (t) => { const incoming = new HttpIncoming(ADVANCED_REQ, SIMPLE_RES); incoming.development = true; - t.true(incoming.development); + t.ok(incoming.development); t.end(); }); @@ -204,7 +202,7 @@ tap.test('PodiumHttpIncoming.js - set illegal value - should throw', (t) => { tap.test('PodiumHttpIncoming.proxy - set value - should set value', (t) => { const incoming = new HttpIncoming(ADVANCED_REQ, SIMPLE_RES); incoming.proxy = true; - t.true(incoming.proxy); + t.ok(incoming.proxy); t.end(); }); @@ -284,8 +282,8 @@ tap.test('PodiumHttpIncoming.toJSON() - call method - should return object witho t.same(result.params, {}); t.same(result.context, {}); t.same(result.view, {}); - t.false(result.proxy); - t.false(result.development); + t.notOk(result.proxy); + t.notOk(result.development); t.equal(result.name, ''); t.same(result.css, []); t.same(result.js, []); diff --git a/tests/utils.js b/tests/utils.js index 0b665f9..7a74d22 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -1,7 +1,5 @@ -'use strict'; - -const tap = require('tap'); -const utils = require('../lib/utils'); +import tap from 'tap'; +import * as utils from '../lib/utils.js' /** * .isString() @@ -9,55 +7,55 @@ const utils = require('../lib/utils'); tap.test('.isString() - no arguments given - should return false', (t) => { const result = utils.isString(); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isString() - arguments is an object - should return false', (t) => { const result = utils.isString({}); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isString() - arguments is an string - should return true', (t) => { const result = utils.isString('function'); - t.true(result); + t.ok(result); t.end(); }); tap.test('.isString() - arguments is an array - should return false', (t) => { const result = utils.isString([]); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isString() - arguments is an boolean - should return false', (t) => { const result = utils.isString(true); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isString() - arguments is an number - should return false', (t) => { const result = utils.isString(42); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isString() - arguments is an function - should return false', (t) => { const result = utils.isString(() => {}); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isString() - arguments is an arrow function - should return false', (t) => { const result = utils.isString(() => {}); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isString() - arguments is an async function - should return false', (t) => { const result = utils.isString(async () => {}); - t.false(result); + t.notOk(result); t.end(); }); @@ -67,55 +65,55 @@ tap.test('.isString() - arguments is an async function - should return false', ( tap.test('.isFunction() - no arguments given - should return false', (t) => { const result = utils.isFunction(); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isFunction() - arguments is an object - should return false', (t) => { const result = utils.isFunction({}); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isFunction() - arguments is an string - should return false', (t) => { const result = utils.isFunction('function'); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isFunction() - arguments is an array - should return false', (t) => { const result = utils.isFunction([]); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isFunction() - arguments is an boolean - should return false', (t) => { const result = utils.isFunction(true); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isFunction() - arguments is an number - should return false', (t) => { const result = utils.isFunction(42); - t.false(result); + t.notOk(result); t.end(); }); tap.test('.isFunction() - arguments is an function - should return true', (t) => { const result = utils.isFunction(() => {}); - t.true(result); + t.ok(result); t.end(); }); tap.test('.isFunction() - arguments is an arrow function - should return true', (t) => { const result = utils.isFunction(() => {}); - t.true(result); + t.ok(result); t.end(); }); tap.test('.isFunction() - arguments is an async function - should return true', (t) => { const result = utils.isFunction(async () => {}); - t.true(result); + t.ok(result); t.end(); }); @@ -302,12 +300,12 @@ tap.test('.uriBuilder() - "extra" is provided - should append "extra"', (t) => { */ tap.test('.uriIsRelative() - "uri" is relative - should return "true"', (t) => { - t.true(utils.uriIsRelative('/manifest.json')); + t.ok(utils.uriIsRelative('/manifest.json')); t.end(); }); tap.test('.uriIsRelative() - "uri" is absolute - should return "false"', (t) => { - t.false(utils.uriIsRelative('http://localhost:7000/manifest.json')); + t.notOk(utils.uriIsRelative('http://localhost:7000/manifest.json')); t.end(); });