Skip to content

Commit fc90d61

Browse files
authored
Switches from yarn to nari (#139)
1 parent 3801276 commit fc90d61

File tree

9 files changed

+89
-14213
lines changed

9 files changed

+89
-14213
lines changed

.github/workflows/build-and-test.yml

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,46 @@ name: Build and test mochapack
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
77

88
jobs:
99
build:
1010
strategy:
1111
matrix:
12-
node: [12, 14]
12+
node: [18, 20]
1313
mocha: [7, 8, 9]
1414
webpack: [4, 5]
1515

16-
name: 'Mocha ${{matrix.mocha}} w/ Webpack ${{matrix.webpack}} w/ Node.js ${{matrix.node}}.x'
16+
name: "Mocha ${{matrix.mocha}} w/ Webpack ${{matrix.webpack}} w/ Node.js ${{matrix.node}}.x"
1717
runs-on: ubuntu-latest
1818

1919
steps:
20-
- uses: actions/checkout@v2
21-
22-
- name: 'Use Node.js ${{matrix.node}}'
23-
uses: actions/setup-node@master
24-
with:
25-
node-version: ${{matrix.node}}.x
26-
27-
- name: Install
28-
run: |
29-
yarn add -D webpack@${{ matrix.webpack }} mocha@${{ matrix.mocha }}
30-
31-
- name: Prepare for tests
32-
run: |
33-
if [ ${{ matrix.webpack }} == 4 ]; then echo -e "// @ts-nocheck\n/*eslint-disable*/\n$(cat src/webpack/util/getAffectedModuleIds.ts)" > src/webpack/util/getAffectedModuleIds.ts; fi
34-
if [ ${{ matrix.webpack }} == 5 ]; then echo -e "// @ts-nocheck\n$(cat src/webpack/util/webpack4GetBuildStats.ts)" > src/webpack/util/webpack4GetBuildStats.ts; fi
35-
36-
- name: Run tests
37-
run: |
38-
yarn cover
39-
40-
- name: Check coverage
41-
run: |
42-
bash <(curl -s https://codecov.io/bash)
20+
- uses: actions/checkout@v2
21+
22+
- name: "Use Node.js ${{matrix.node}}"
23+
uses: actions/setup-node@master
24+
with:
25+
node-version: ${{matrix.node}}.x
26+
27+
- name: Install
28+
run: |
29+
npm i -g nari
30+
nari
31+
32+
- name: Change webpack and mocha versions
33+
run: |
34+
nari add -D webpack@${{ matrix.webpack }} mocha@${{ matrix.mocha }}
35+
36+
- name: Prepare for tests
37+
run: |
38+
if [ ${{ matrix.webpack }} == 4 ]; then echo -e "// @ts-nocheck\n/*eslint-disable*/\n$(cat src/webpack/util/getAffectedModuleIds.ts)" > src/webpack/util/getAffectedModuleIds.ts; fi
39+
if [ ${{ matrix.webpack }} == 5 ]; then echo -e "// @ts-nocheck\n$(cat src/webpack/util/webpack4GetBuildStats.ts)" > src/webpack/util/webpack4GetBuildStats.ts; fi
40+
41+
- name: Run tests
42+
run: |
43+
nari cover
44+
45+
- name: Check coverage
46+
run: |
47+
bash <(curl -s https://codecov.io/bash)

.pinyarn.js

Lines changed: 0 additions & 144 deletions
This file was deleted.

.yarnrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.yarnrc.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
# mochapack [![Join the chat at https://gitter.im/sysgears/mochapack](https://badges.gitter.im/sysgears/mochapack.svg)](https://gitter.im/sysgears/mochapack?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![npm package][npm-badge]][npm] [![Build Status Linux][build-badge]][build] [![Build Status Windows][build-badge-windows]][build-windows] [![codecov][codecov-badge]][codecov] [![Twitter Follow](https://img.shields.io/twitter/follow/sysgears.svg?style=social)](https://twitter.com/sysgears)
1+
# mochapack [![Join the chat at https://gitter.im/sysgears/mochapack](https://badges.gitter.im/sysgears/mochapack.svg)](https://gitter.im/sysgears/mochapack?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![npm package][npm-badge]][npm] [![Build Status Linux][build-badge]][build] [![Build Status Windows][build-badge-windows]][build-windows] [![codecov][codecov-badge]][codecov] [![Twitter Follow](https://img.shields.io/twitter/follow/sysgears.svg?style=social)](https://twitter.com/sysgears)
22

33
This project is a fork of [mocha-webpack](https://github.com/zinserjan/mocha-webpack). We have created this fork since there is no visible activity from original author for a long time.
44

55
> mocha test runner with integrated webpack precompiler
66
77
mochapack is basically a wrapper around the following command...
8+
89
```bash
910
$ webpack test.js output.js && mocha output.js
1011
```
1112

12-
... but in a much more *powerful* & *optimized* way.
13+
... but in a much more _powerful_ & _optimized_ way.
1314

1415
![CLI](./docs/media/cli-test-success.png)
1516

1617
mochapack ...
18+
1719
- precompiles your test files automatically with webpack before executing tests
1820
- handles source-maps automatically for you
1921
- does not write any files to disk
2022
- understands globs & all other stuff as test entries like mocha
2123

2224
Benefits over plain mocha
25+
2326
- has nearly the same CLI as mocha
2427
- you don't rely on hacky solutions to mock all benefits from webpack, like path resolution
2528
- mochapack provides a much better watch mode than mocha
@@ -37,12 +40,14 @@ If any build errors happens, they will be shown like below
3740
## Which version works with mochapack?
3841

3942
mochapack works with
43+
4044
- webpack in versions `4.x.x` - `5.x.x`
4145
- mocha in versions `5.x.x` - `9.x.x`
4246

4347
## Installation
4448

4549
Install mochapack via npm install
50+
4651
```bash
4752
$ npm install webpack mocha mochapack --save-dev
4853
```
@@ -64,9 +69,10 @@ run all tests by glob
6469
```bash
6570
mochapack "test/**/*.js"
6671
```
72+
6773
**Note:** You may noticed the quotes around the glob pattern. That's unfortunately necessary as most terminals will resolve globs automatically.
6874

69-
run all tests in directory "test" matching the file pattern *.test.js (add `--recursive` to include subdirectories)
75+
run all tests in directory "test" matching the file pattern \*.test.js (add `--recursive` to include subdirectories)
7076

7177
```bash
7278
mochapack --glob "*.test.js" test
@@ -78,6 +84,17 @@ Watch mode? just add `--watch`
7884
mochapack --watch test
7985
```
8086

87+
## Contributing
88+
89+
This project uses `nari` package manager to have reproducible builds without resorting to lockfiles, it uses `lockTime` field in `package.json` instead.
90+
91+
To install `nari` execute:
92+
`npm i -g nari`
93+
94+
And then `nari` to install the project.
95+
96+
To run project scripts use `nari script_name`, for example `nari test` to run unit tests.
97+
8198
## License
8299

83100
This source code is licensed under the [MIT] license.<br/>
@@ -90,7 +107,7 @@ Copyright &copy; 2018 [SysGears (Cyprus) Limited].
90107
[build-windows]: https://ci.appveyor.com/project/sysgears/mochapack
91108
[npm-badge]: https://img.shields.io/npm/v/mochapack.svg?style=flat-square
92109
[npm]: https://www.npmjs.org/package/mochapack
93-
[codecov-badge]:https://codecov.io/gh/sysgears/mochapack/branch/master/graph/badge.svg
110+
[codecov-badge]: https://codecov.io/gh/sysgears/mochapack/branch/master/graph/badge.svg
94111
[codecov]: https://codecov.io/gh/sysgears/mochapack
95112
[sysgears (cyprus) limited]: https://sysgears.com
96113
[mit]: LICENSE.md

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
"scripts": {
1616
"clean-lib": "del-cli \"lib/**\" \"!lib\" \"!lib/reporters\" \"!lib/utils.js\" \"!lib/entry.js\" \"!lib/reporters/base.js\"",
1717
"clean-tmp": "del-cli \".tmp/**\"",
18-
"build": "yarn clean-lib && tsc",
18+
"build": "nari clean-lib && tsc",
1919
"format": "prettier '{src,test}/**/*' ./*.json --write --loglevel warn",
2020
"lint": "eslint src/**/*.ts test/**/*.ts --fix",
21-
"test": "yarn clean-tmp && yarn build && ts-mocha --timeout 10000 --recursive --require @babel/register --exit \"{test,src}/**/*.test.ts\"",
22-
"cover": "cross-env BABEL_ENV=coverage nyc --reporter=lcov --reporter=text yarn test",
23-
"posttest": "yarn format && yarn lint",
21+
"test": "nari clean-tmp && nari build && ts-mocha --timeout 10000 --recursive --require @babel/register --exit \"{test,src}/**/*.test.ts\"",
22+
"cover": "cross-env BABEL_ENV=coverage nyc --reporter=lcov --reporter=text nari test",
23+
"posttest": "nari format && nari lint",
2424
"docs:clean": "del-cli _book",
25-
"docs:build": "yarn docs:clean && node ./gitbook-cli build",
25+
"docs:build": "nari docs:clean && node ./gitbook-cli build",
2626
"docs:watch": "node ./gitbook-cli serve --port 3000",
2727
"docs:deploy": "gh-pages -d _book",
28-
"prepack": "yarn build",
29-
"postpublish": "yarn docs:deploy",
28+
"prepack": "nari build",
29+
"postpublish": "nari docs:deploy",
3030
"release": "np",
3131
"watch": "tsc -w"
3232
},
@@ -61,7 +61,7 @@
6161
"@types/chai": "^4.2.7",
6262
"@types/lodash": "^4.14.149",
6363
"@types/mocha": "^9.1.0",
64-
"@types/node": "^12.12.17",
64+
"@types/node": "^22.7.4",
6565
"@types/sinon": "^9.0.0",
6666
"@types/sinon-chai": "^3.2.4",
6767
"@types/yargs": "^15.0.4",
@@ -160,5 +160,6 @@
160160
"tunnel-agent": ">=0.6.0",
161161
"hoek": "^4.2.1",
162162
"cryptiles": "^4.1.3"
163-
}
164-
}
163+
},
164+
"lockTime": "2024-10-02T13:05:25.268Z"
165+
}

src/runner/runnerUtils/createWebpackConfig/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import {
55
has as _has,
66
merge as _merge
77
} from 'lodash'
8-
import { Configuration, WebpackPluginInstance, RuleSetRule } from 'webpack'
8+
import {
9+
Configuration,
10+
WebpackPluginInstance,
11+
Compiler,
12+
RuleSetRule
13+
} from 'webpack'
914
import { glob } from '../../../util/glob'
1015
import { EntryConfig } from '../../../webpack/loader/entryLoader'
1116
import { buildProgressPlugin } from '../../../webpack/plugin/buildProgressPlugin'
@@ -48,7 +53,13 @@ const getPublicPath = (
4853
const buildPluginsArray = (
4954
webpackConfig: Configuration,
5055
interactive: boolean
51-
): WebpackPluginInstance[] => {
56+
): (
57+
| false
58+
| ''
59+
| 0
60+
| WebpackPluginInstance
61+
| ((this: Compiler, compiler: Compiler) => void)
62+
)[] => {
5263
const plugins = webpackConfig.plugins || []
5364

5465
if (interactive) {

0 commit comments

Comments
 (0)