Skip to content

Commit

Permalink
feat: mock streams (#9)
Browse files Browse the repository at this point in the history
* streams part 1

* stream works in test

* ndjson stream mocking

* publish
  • Loading branch information
LoaderB0T authored Apr 15, 2024
1 parent 5be846e commit e60b8b5
Show file tree
Hide file tree
Showing 59 changed files with 708 additions and 507 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
lib
junit.xml
dist
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
src
test
.vscode
.eslintignore
.eslintrc.json
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ Also, when you are prototyping a new feature, you might want to mock a whole API

✅ Supports failing of stubbed requests

✅ No production dependencies
✅ Supports EventSource & ndjson

✅ Supports WebSockets (beta)

✅ No production dependencies (You need to have playwright installed, of course)

✅ ESM & CJS exports

Expand Down
2 changes: 1 addition & 1 deletion fix-cjs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';

fs.writeFileSync(
'./lib/cjs/package.json',
'./dist/cjs/package.json',
`{
"type": "CommonJS"
}`
Expand Down
16 changes: 0 additions & 16 deletions jest.config.js

This file was deleted.

29 changes: 29 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { JestConfigWithTsJest, pathsToModuleNameMapper } from 'ts-jest';
import { defaultsESM } from 'ts-jest/presets';
import { compilerOptions } from './tsconfig.base.json';

// Changes the tsconfig used for tests to tsconfig.spec.json
const transform = defaultsESM.transform!;
Object.keys(transform).forEach(key => {
const value = transform[key];
if (Array.isArray(value)) {
value[1].tsconfig = './tsconfig.spec.json';
}
});

const config: JestConfigWithTsJest = {
roots: ['./test'],
testTimeout: 90000,
transform: {
...transform,
},
extensionsToTreatAsEsm: ['.ts'],
modulePaths: [compilerOptions.baseUrl],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
...pathsToModuleNameMapper(compilerOptions.paths),
},
reporters: ['default', ['jest-junit', { outputName: 'junit.xml' }]],
};

export default config;
30 changes: 19 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-network-stub",
"version": "6.2.0",
"version": "7.0.1",
"repository": "https://github.com/LoaderB0T/easy-network-stub.git",
"author": {
"name": "Janik Schumacher (LoaderB0T)",
Expand All @@ -10,37 +10,45 @@
"type": "module",
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
"import": "./dist/esm/lib/index.js",
"require": "./dist/cjs/lib/index.js"
},
"ws": {
"import": "./lib/esm/ws/index.js.js",
"require": "./lib/cjs/ws/index.js.js"
"./ws": {
"import": "./dist/esm/ws/index.js",
"require": "./dist/cjs/ws/index.js"
},
"./stream": {
"import": "./dist/esm/stream/index.js",
"require": "./dist/cjs/stream/index.js"
}
},
"main": "./lib/cjs/index.js",
"main": "./dist/cjs/index.js",
"prettier": "@awdware/prettier-config",
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "pnpm eslint ./src/**",
"test": "jest",
"prebuild": "pnpm rimraf lib",
"prebuild": "pnpm rimraf dist",
"build": "pnpm build-esm && pnpm build-cjs",
"build-base": "tsc -p .",
"build-esm": "pnpm build-base --outDir lib/esm",
"build-cjs": "pnpm build-base --outDir lib/cjs --module commonjs && pnpm fix-cjs",
"build-esm": "pnpm build-base --outDir dist/esm",
"build-cjs": "pnpm build-base --outDir dist/cjs --module commonjs && pnpm fix-cjs",
"fix-cjs": "node --loader ts-node/esm ./fix-cjs.ts"
},
"devDependencies": {
"@awdware/eslint-config-base": "^1.2.0",
"@awdware/eslint-config-nodejs": "^1.0.0",
"@awdware/prettier-config": "^1.0.0",
"@types/event-source-polyfill": "^1.0.5",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"eslint": "^9.0.0",
"can-ndjson-stream": "^1.0.2",
"eslint": "^8.57.0",
"event-source-polyfill": "^1.0.31",
"eventsource": "^2.0.2",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"prettier": "^3.2.5",
Expand Down
Loading

0 comments on commit e60b8b5

Please sign in to comment.