Skip to content

Commit

Permalink
Module packing for cjs, mjs support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ymaril committed Mar 26, 2023
1 parent a4465b6 commit 6a6c838
Show file tree
Hide file tree
Showing 23 changed files with 238 additions and 46 deletions.
4 changes: 0 additions & 4 deletions .npmignore

This file was deleted.

27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ let-given will not execute functions for variables that are redefined deeper in

```js
letGiven("name", async () => {
return await slowNameGenerator.generate(); // this code will not execute
// this code will not execute
const slowNameGenerator = await slowGenerator.generateSlowNameGenerator();
return await slowNameGenerator.generate();
});
describe("with simple name", () => {
letGiven("name", () => "John");
Expand All @@ -162,11 +164,11 @@ let-given has strong typescript typing

```js
// In a typescript, you must specify a test framework
import useGiven from "let-given/dist/jasmine"; // There are available: "let-given/dist/jasmine", "let-given/dist/mocha", "let-given/dist/jest"
import useGiven from "let-given/jasmine"; // There are available: "let-given/jasmine", "let-given/mocha", "let-given/jest"

interface Given {
name: string
userParams: object
name: string,
userParams: object,
user: User
}

Expand Down Expand Up @@ -233,7 +235,7 @@ useGivenWithWrapper will return the wrapped functions in the same fields in whic

## Alternatives

There are several work packages that implement context variables
There are several packages that implement context variables
- [bdd-lazy-var](https://github.com/stalniy/bdd-lazy-var)
- [Given2](https://github.com/tatyshev/given2)
- [givens](https://github.com/enova/givens)
Expand All @@ -249,7 +251,7 @@ These are a few advantages of using the rspec approach for context creation:

### Don't repeat yourself

let-given makes it possible to describe only that part of the context that is directly relevant to the test. No need to call fixtures at the beginning of each assertation
let-given makes it possible to describe only that part of the context that is directly relevant to the test. No need to call fixtures or something at the beginning of each assertation

### Test order

Expand All @@ -269,20 +271,21 @@ You can create issues on github with a description of the issue.
You can also create a pull request with fixes.
It is important that all tests are passed on the pull request branch.

There are two test folders here: dev and dist
There are two test folders: dev and dist
- dev tests are designed to test functionality at the development stage
- dist tests to test an already compiled distribution.

Run only dev tests
```bash
npm run test
yarn install
yarn test
```
Run only dev tests.

Run dist test
```bash
npm run build
npm run test:dist
yarn build # build dist and copy it to node_modules
yarn test:dist # test let-given package from node_modules folder
```
Run dist test

## License

Expand Down
13 changes: 13 additions & 0 deletions config/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"files": [
"../src/index.ts",
"../src/jasmine/index.ts",
"../src/mocha/index.ts",
"../src/jest/index.ts"
],
"exclude": [
"../tests/**/*",
"../dist/**/*"
],
}
10 changes: 10 additions & 0 deletions config/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"lib": ["ES6", "DOM"],
"target": "ES6",
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "../dist/lib/cjs",
}
}
10 changes: 10 additions & 0 deletions config/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"lib": ["ES2022", "DOM"],
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "NodeNext",
"outDir": "../dist/lib/esm"
}
}
7 changes: 7 additions & 0 deletions config/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"declarationDir": "../dist/lib/types",
"declaration": true
}
}
85 changes: 81 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,75 @@
{
"name": "let-given",
"version": "0.2.3",
"version": "0.3.0",
"license": "MIT",
"main": "dist/useGiven.js",
"typings": "dist/useGiven.d.ts",
"types": "./lib/types/index.d.ts",
"main": "./lib/cjs/index.js",
"repository": "github:Ymaril/let-given",
"typesVersions": {
"*": {
".": [
"./lib/types/index.d.ts"
],
"jasmine": [
"./lib/types/jasmine/index.d.ts"
],
"mocha": [
"./lib/types/mocha/index.d.ts"
],
"jest": [
"./lib/types/jest/index.d.ts"
]
}
},
"exports": {
".": {
"import": {
"types": "./lib/types/index.d.ts",
"default": "./lib/esm/index.js"
},
"require": {
"types": "./lib/types/index.d.ts",
"default": "./lib/cjs/index.js"
},
"default": "./lib/cjs/index.js"
},
"./jasmine": {
"import": {
"types": "./lib/types/jasmine/index.d.ts",
"default": "./lib/esm/jasmine/index.js"
},
"require": {
"types": "./lib/types/jasmine/index.d.ts",
"default": "./lib/cjs/jasmine/index.js"
},
"default": "./lib/cjs/jasmine/index.js"
},
"./mocha": {
"import": {
"types": "./lib/types/mocha/index.d.ts",
"default": "./lib/esm/mocha/index.js"
},
"require": {
"types": "./lib/types/mocha/index.d.ts",
"default": "./lib/cjs/mocha/index.js"
},
"default": "./lib/cjs/mocha/index.js"
},
"./jest": {
"import": {
"types": "./lib/types/jest/index.d.ts",
"default": "./lib/esm/jest/index.js"
},
"require": {
"types": "./lib/types/jest/index.d.ts",
"default": "./lib/cjs/jest/index.js"
},
"default": "./lib/cjs/jest/index.js"
}
},
"files": [
"lib/**/*"
],
"scripts": {
"test": "yarn test:dev",
"test:dev": "yarn test:dev:jasmine && yarn test:dev:mocha && yarn test:dev:jest",
Expand All @@ -15,13 +80,25 @@
"test:dist:jasmine": "jasmine --config=jasmine.json \"tests/dist/jasmine/**/*\"",
"test:dist:mocha": "mocha --require ts-node/register \"tests/dist/mocha/**/*\"",
"test:dist:jest": "jest \"tests/dist/jest/.*\"",
"build": "tsc --project tsconfig.build.json"
"clean": "yarn clean:dist && yarn clean:module",
"clean:dist": "rm -rf ./dist",
"clean:module": "rm -rf ./node_modules/let-given",
"build": "yarn clean && yarn build:code && yarn build:meta && yarn build:copy_module",
"build:code": "yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "tsc -p config/tsconfig.esm.json",
"build:cjs": "tsc -p config/tsconfig.cjs.json",
"build:types": "tsc -p config/tsconfig.types.json --emitDeclarationOnly",
"build:meta": "yarn build:package && yarn build:readme",
"build:package": "npx clear-package-json package.json -o dist/package.json",
"build:readme": "cp README.md dist/README.md",
"build:copy_module": "cp -r dist node_modules/let-given-dist"
},
"devDependencies": {
"@types/jasmine": "^4.0.3",
"@types/jest": "^29.4.0",
"@types/mocha": "^10.0.1",
"@types/node": "^17.0.39",
"clean-publish": "^4.1.1",
"jasmine": "^4.1.0",
"jest": "^29.5.0",
"mocha": "^10.2.0",
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/jasmine/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { baseUseGiven } from "../useGiven";
import { baseUseGiven } from "..";
import itWrapper, { JasmineWrappedItScope } from "./itWrapper";

export default function useGiven<T extends Record<string, any>>() {
export function useGiven<T extends Record<string, any>>() {
return baseUseGiven<T, JasmineWrappedItScope<T>>(itWrapper);
}

export default useGiven;
6 changes: 4 additions & 2 deletions src/jest/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { baseUseGiven } from "../useGiven";
import { baseUseGiven } from "..";
import itWrapper, { JestWrappedItScope } from "./itWrapper";

export default function useGiven<T extends Record<string, any>>() {
export function useGiven<T extends Record<string, any>>() {
return baseUseGiven<T, JestWrappedItScope<T>>(itWrapper);
}

export default useGiven;
6 changes: 4 additions & 2 deletions src/mocha/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { baseUseGiven } from "../useGiven";
import { baseUseGiven } from "..";
import itWrapper, { MochaWrappedItScope } from "./itWrapper";

export default function useGiven<T extends Record<string, any>>() {
export function useGiven<T extends Record<string, any>>() {
return baseUseGiven<T, MochaWrappedItScope<T>>(itWrapper);
}

export default useGiven;
2 changes: 1 addition & 1 deletion tests/dev/jasmine/custom-wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGivenWithWrapper } from "../../../src/useGiven";
import { useGivenWithWrapper } from "../../../src";

const testUI = {
test: global.it,
Expand Down
2 changes: 1 addition & 1 deletion tests/dist/jasmine/custom-wrapper.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { useGivenWithWrapper } = require("../../../dist/useGiven");
const { useGivenWithWrapper } = require("let-given-dist");

const testUI = {
test: global.it,
Expand Down
2 changes: 1 addition & 1 deletion tests/dist/jasmine/custom-wrapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGivenWithWrapper } from "../../../dist/useGiven";
import { useGivenWithWrapper } from "let-given-dist";

const testUI = {
test: global.it,
Expand Down
2 changes: 1 addition & 1 deletion tests/dist/jasmine/letGiven.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { useGiven } = require("../../../dist/useGiven");
const { useGiven } = require("let-given-dist");

const { letGiven, it } = useGiven();

Expand Down
2 changes: 1 addition & 1 deletion tests/dist/jasmine/letGiven.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useGiven from "../../../dist/jasmine";
import useGiven from "let-given-dist/jasmine";

const { letGiven, it, xit } = useGiven<{
five: number;
Expand Down
2 changes: 1 addition & 1 deletion tests/dist/jest/letGiven.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { useGiven } = require("../../../dist/useGiven");
const { useGiven } = require("let-given-dist");

const { letGiven, it } = useGiven();

Expand Down
2 changes: 1 addition & 1 deletion tests/dist/jest/letGiven.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useGiven from "../../../dist/jest";
import useGiven from "let-given-dist/jest";

const { letGiven, it, xit } = useGiven<{
five: number;
Expand Down
2 changes: 1 addition & 1 deletion tests/dist/mocha/letGiven.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { useGiven } = require("../../../dist/useGiven");
const { useGiven } = require("let-given-dist");
const assert = require("assert");

const { letGiven, it } = useGiven();
Expand Down
2 changes: 1 addition & 1 deletion tests/dist/mocha/letGiven.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useGiven from "../../../src/mocha";
import useGiven from "let-given-dist/mocha";
import assert from "assert";

const { letGiven, it } = useGiven<{
Expand Down
4 changes: 0 additions & 4 deletions tsconfig.build.json

This file was deleted.

8 changes: 3 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"removeComments": false,
"outDir": "dist"
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
}
}
}
Loading

0 comments on commit 6a6c838

Please sign in to comment.