-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- enhance tests
- Loading branch information
Showing
5 changed files
with
68 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
node_modules | ||
dist | ||
|
||
# npm pack default output | ||
krutoo-fetch-tools-0.0.0.tgz |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
{ | ||
"name": "fetch-tools-tests", | ||
"version": "0.0.0", | ||
"description": "Tests", | ||
"private": true, | ||
"scripts": { | ||
"preparing": "npm i --no-save ../krutoo-fetch-tools-0.0.0.tgz", | ||
"test": "npm run test:cjs && npm run test:mjs", | ||
"test:cjs": "node test.cjs", | ||
"test:mjs": "node test.mjs" | ||
}, | ||
"dependencies": { | ||
"@krutoo/fetch-tools": "file:.." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
const { configureFetch, applyMiddleware } = require('@krutoo/fetch-tools'); | ||
const { validateStatus } = require('@krutoo/fetch-tools/middleware'); | ||
const fs = require('fs/promises'); | ||
const path = require('node:path'); | ||
const assert = require('node:assert'); | ||
|
||
console.assert(typeof configureFetch === 'function'); | ||
console.assert(typeof applyMiddleware === 'function'); | ||
async function testExports() { | ||
const pkg = JSON.parse(await fs.readFile('../package.json', 'utf-8')); | ||
|
||
const myFetch = configureFetch( | ||
fetch, | ||
applyMiddleware(validateStatus(status => status >= 200 && status < 300)), | ||
); | ||
assert.equal(pkg.name, '@krutoo/fetch-tools'); | ||
|
||
myFetch('https://jsonplaceholder.typicode.com/posts/1') | ||
.then(res => res.json()) | ||
.then(console.log); | ||
for (const pathname of Object.keys(pkg.exports)) { | ||
const specifier = path.join(pkg.name, pathname); | ||
|
||
assert.doesNotThrow(() => require(specifier)); | ||
} | ||
} | ||
|
||
async function testBaseFunctionality() { | ||
const { configureFetch, applyMiddleware } = require('@krutoo/fetch-tools'); | ||
const { validateStatus } = require('@krutoo/fetch-tools/middleware'); | ||
|
||
assert.equal(typeof configureFetch, 'function'); | ||
assert.equal(typeof applyMiddleware, 'function'); | ||
|
||
const myFetch = configureFetch(fetch, applyMiddleware(validateStatus(status => status === 200))); | ||
|
||
assert.equal(typeof myFetch, 'function'); | ||
} | ||
|
||
Promise.resolve().then(testExports).then(testBaseFunctionality); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
import { configureFetch, applyMiddleware } from '@krutoo/fetch-tools'; | ||
import { validateStatus } from '@krutoo/fetch-tools/middleware'; | ||
import fs from 'fs/promises'; | ||
import path from 'node:path'; | ||
import assert from 'node:assert'; | ||
|
||
console.assert(typeof configureFetch === 'function'); | ||
console.assert(typeof applyMiddleware === 'function'); | ||
async function testExports() { | ||
const pkg = JSON.parse(await fs.readFile('../package.json', 'utf-8')); | ||
|
||
const myFetch = configureFetch( | ||
fetch, | ||
applyMiddleware(validateStatus(status => status >= 200 && status < 300)), | ||
); | ||
assert.equal(pkg.name, '@krutoo/fetch-tools'); | ||
|
||
myFetch('https://jsonplaceholder.typicode.com/posts/1') | ||
.then(res => res.json()) | ||
.then(console.log); | ||
for (const pathname of Object.keys(pkg.exports)) { | ||
const specifier = path.join(pkg.name, pathname); | ||
|
||
await assert.doesNotReject(() => import(specifier)); | ||
} | ||
} | ||
|
||
async function testBaseFunctionality() { | ||
const { configureFetch, applyMiddleware } = await import('@krutoo/fetch-tools'); | ||
const { validateStatus } = await import('@krutoo/fetch-tools/middleware'); | ||
|
||
assert.equal(typeof configureFetch, 'function'); | ||
assert.equal(typeof applyMiddleware, 'function'); | ||
|
||
const myFetch = configureFetch(fetch, applyMiddleware(validateStatus(status => status === 200))); | ||
|
||
assert.equal(typeof myFetch, 'function'); | ||
} | ||
|
||
Promise.resolve().then(testExports).then(testBaseFunctionality); |