Skip to content

Commit

Permalink
Switches from yarn to nari (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
larixer authored Oct 3, 2024
1 parent 3801276 commit fc90d61
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 14,213 deletions.
57 changes: 31 additions & 26 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@ name: Build and test mochapack

on:
push:
branches: [ master ]
branches: [master]
pull_request:

jobs:
build:
strategy:
matrix:
node: [12, 14]
node: [18, 20]
mocha: [7, 8, 9]
webpack: [4, 5]

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

steps:
- uses: actions/checkout@v2

- name: 'Use Node.js ${{matrix.node}}'
uses: actions/setup-node@master
with:
node-version: ${{matrix.node}}.x

- name: Install
run: |
yarn add -D webpack@${{ matrix.webpack }} mocha@${{ matrix.mocha }}
- name: Prepare for tests
run: |
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
if [ ${{ matrix.webpack }} == 5 ]; then echo -e "// @ts-nocheck\n$(cat src/webpack/util/webpack4GetBuildStats.ts)" > src/webpack/util/webpack4GetBuildStats.ts; fi
- name: Run tests
run: |
yarn cover
- name: Check coverage
run: |
bash <(curl -s https://codecov.io/bash)
- uses: actions/checkout@v2

- name: "Use Node.js ${{matrix.node}}"
uses: actions/setup-node@master
with:
node-version: ${{matrix.node}}.x

- name: Install
run: |
npm i -g nari
nari
- name: Change webpack and mocha versions
run: |
nari add -D webpack@${{ matrix.webpack }} mocha@${{ matrix.mocha }}
- name: Prepare for tests
run: |
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
if [ ${{ matrix.webpack }} == 5 ]; then echo -e "// @ts-nocheck\n$(cat src/webpack/util/webpack4GetBuildStats.ts)" > src/webpack/util/webpack4GetBuildStats.ts; fi
- name: Run tests
run: |
nari cover
- name: Check coverage
run: |
bash <(curl -s https://codecov.io/bash)
144 changes: 0 additions & 144 deletions .pinyarn.js

This file was deleted.

1 change: 0 additions & 1 deletion .yarnrc

This file was deleted.

4 changes: 0 additions & 4 deletions .yarnrc.yml

This file was deleted.

25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# 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)
# 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)

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.

> mocha test runner with integrated webpack precompiler
mochapack is basically a wrapper around the following command...

```bash
$ webpack test.js output.js && mocha output.js
```

... but in a much more *powerful* & *optimized* way.
... but in a much more _powerful_ & _optimized_ way.

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

mochapack ...

- precompiles your test files automatically with webpack before executing tests
- handles source-maps automatically for you
- does not write any files to disk
- understands globs & all other stuff as test entries like mocha

Benefits over plain mocha

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

mochapack works with

- webpack in versions `4.x.x` - `5.x.x`
- mocha in versions `5.x.x` - `9.x.x`

## Installation

Install mochapack via npm install

```bash
$ npm install webpack mocha mochapack --save-dev
```
Expand All @@ -64,9 +69,10 @@ run all tests by glob
```bash
mochapack "test/**/*.js"
```

**Note:** You may noticed the quotes around the glob pattern. That's unfortunately necessary as most terminals will resolve globs automatically.

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

```bash
mochapack --glob "*.test.js" test
Expand All @@ -78,6 +84,17 @@ Watch mode? just add `--watch`
mochapack --watch test
```

## Contributing

This project uses `nari` package manager to have reproducible builds without resorting to lockfiles, it uses `lockTime` field in `package.json` instead.

To install `nari` execute:
`npm i -g nari`

And then `nari` to install the project.

To run project scripts use `nari script_name`, for example `nari test` to run unit tests.

## License

This source code is licensed under the [MIT] license.<br/>
Expand All @@ -90,7 +107,7 @@ Copyright &copy; 2018 [SysGears (Cyprus) Limited].
[build-windows]: https://ci.appveyor.com/project/sysgears/mochapack
[npm-badge]: https://img.shields.io/npm/v/mochapack.svg?style=flat-square
[npm]: https://www.npmjs.org/package/mochapack
[codecov-badge]:https://codecov.io/gh/sysgears/mochapack/branch/master/graph/badge.svg
[codecov-badge]: https://codecov.io/gh/sysgears/mochapack/branch/master/graph/badge.svg
[codecov]: https://codecov.io/gh/sysgears/mochapack
[sysgears (cyprus) limited]: https://sysgears.com
[mit]: LICENSE.md
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
"scripts": {
"clean-lib": "del-cli \"lib/**\" \"!lib\" \"!lib/reporters\" \"!lib/utils.js\" \"!lib/entry.js\" \"!lib/reporters/base.js\"",
"clean-tmp": "del-cli \".tmp/**\"",
"build": "yarn clean-lib && tsc",
"build": "nari clean-lib && tsc",
"format": "prettier '{src,test}/**/*' ./*.json --write --loglevel warn",
"lint": "eslint src/**/*.ts test/**/*.ts --fix",
"test": "yarn clean-tmp && yarn build && ts-mocha --timeout 10000 --recursive --require @babel/register --exit \"{test,src}/**/*.test.ts\"",
"cover": "cross-env BABEL_ENV=coverage nyc --reporter=lcov --reporter=text yarn test",
"posttest": "yarn format && yarn lint",
"test": "nari clean-tmp && nari build && ts-mocha --timeout 10000 --recursive --require @babel/register --exit \"{test,src}/**/*.test.ts\"",
"cover": "cross-env BABEL_ENV=coverage nyc --reporter=lcov --reporter=text nari test",
"posttest": "nari format && nari lint",
"docs:clean": "del-cli _book",
"docs:build": "yarn docs:clean && node ./gitbook-cli build",
"docs:build": "nari docs:clean && node ./gitbook-cli build",
"docs:watch": "node ./gitbook-cli serve --port 3000",
"docs:deploy": "gh-pages -d _book",
"prepack": "yarn build",
"postpublish": "yarn docs:deploy",
"prepack": "nari build",
"postpublish": "nari docs:deploy",
"release": "np",
"watch": "tsc -w"
},
Expand Down Expand Up @@ -61,7 +61,7 @@
"@types/chai": "^4.2.7",
"@types/lodash": "^4.14.149",
"@types/mocha": "^9.1.0",
"@types/node": "^12.12.17",
"@types/node": "^22.7.4",
"@types/sinon": "^9.0.0",
"@types/sinon-chai": "^3.2.4",
"@types/yargs": "^15.0.4",
Expand Down Expand Up @@ -160,5 +160,6 @@
"tunnel-agent": ">=0.6.0",
"hoek": "^4.2.1",
"cryptiles": "^4.1.3"
}
}
},
"lockTime": "2024-10-02T13:05:25.268Z"
}
15 changes: 13 additions & 2 deletions src/runner/runnerUtils/createWebpackConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
has as _has,
merge as _merge
} from 'lodash'
import { Configuration, WebpackPluginInstance, RuleSetRule } from 'webpack'
import {
Configuration,
WebpackPluginInstance,
Compiler,
RuleSetRule
} from 'webpack'
import { glob } from '../../../util/glob'
import { EntryConfig } from '../../../webpack/loader/entryLoader'
import { buildProgressPlugin } from '../../../webpack/plugin/buildProgressPlugin'
Expand Down Expand Up @@ -48,7 +53,13 @@ const getPublicPath = (
const buildPluginsArray = (
webpackConfig: Configuration,
interactive: boolean
): WebpackPluginInstance[] => {
): (
| false
| ''
| 0
| WebpackPluginInstance
| ((this: Compiler, compiler: Compiler) => void)
)[] => {
const plugins = webpackConfig.plugins || []

if (interactive) {
Expand Down
Loading

0 comments on commit fc90d61

Please sign in to comment.