Skip to content

Commit

Permalink
Merge pull request #16976 from webpack/chore-improve-our-tooling
Browse files Browse the repository at this point in the history
chore: fix prettier
  • Loading branch information
TheLarkInn committed Apr 14, 2023
2 parents c349542 + 3068fb6 commit 5579b56
Show file tree
Hide file tree
Showing 163 changed files with 366 additions and 428 deletions.
26 changes: 14 additions & 12 deletions .eslintignore
@@ -1,26 +1,28 @@
# Ignore node_modules
node_modules
# Ignore some test files
test/**/*.*
!test/*.js
!test/**/webpack.config.js
!test/**/test.config.js
!test/**/test.filter.js
test/cases/parsing/es2022/test.filter.js
!test/**/errors.js
!test/**/warnings.js
!test/**/deprecations.js
!test/helpers/*.*

# Ignore some folders
benchmark
coverage

# Ignore generated files
*.check.js

# Ignore not supported files
!.*.js
.eslintrc.js
*.d.ts

# Ignore precompiled schemas
schemas/**/*.check.js

# Ignore some test files
test/*
!test/*Cases
!test/helpers
!test/*.js
test/*Cases/**/*.js
!test/*Cases/**/webpack.config.js

# Ignore some examples files
examples/**/*.js
!examples/*/webpack.config.js
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Expand Up @@ -2,7 +2,7 @@
<!-- Before creating an issue please make sure you are using the latest version of webpack. -->
<!-- Also consider trying the webpack@beta version, maybe it's already fixed. -->

**Do you want to request a *feature* or report a *bug*?**
**Do you want to request a _feature_ or report a _bug_?**

<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). -->
<!-- Issues which contain questions or support requests will be closed. -->
Expand Down
7 changes: 2 additions & 5 deletions .github/ISSUE_TEMPLATE/Bug_report.md
Expand Up @@ -15,10 +15,8 @@ about: Create a report to help us improve

**What is the current behavior?**


**If the current behavior is a bug, please provide the steps to reproduce.**


<!-- A great way to do this is to provide your configuration via a GitHub repository -->
<!-- The most helpful is a minimal reproduction with instructions on how to reproduce -->
<!-- Repositories with too many files or large `webpack.config.js` files are not suitable -->
Expand All @@ -28,12 +26,11 @@ about: Create a report to help us improve

**What is the expected behavior?**


<!-- "It should work" is not a helpful explanation -->
<!-- Explain exactly how it should behave -->

**Other relevant information:**
webpack version:
Node.js version:
Operating System:
Node.js version:
Operating System:
Additional tools:
4 changes: 0 additions & 4 deletions .github/ISSUE_TEMPLATE/Feature_request.md
@@ -1,7 +1,6 @@
---
name: Feature request
about: Suggest an idea for this project

---

<!-- Please don't delete this template or we'll close your issue -->
Expand All @@ -16,12 +15,9 @@ about: Suggest an idea for this project

**What is the expected behavior?**


**What is motivation or use case for adding/changing the behavior?**


**How should this be implemented in your opinion?**


**Are you willing to work on this yourself?**
yes
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/Other.md
@@ -1,7 +1,6 @@
---
name: Other
about: Something else

---

<!-- Bug reports and Feature requests must use other templates, or will be closed -->
Expand Down
8 changes: 6 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -4,10 +4,14 @@
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
<!-- Try to link to an open issue for more information. -->

## Summary
## Summary

<!-- cspell:disable-next-line -->

copilot:summary

## Details
## Details

<!-- cspell:disable-next-line -->

copilot:walkthrough
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE_ORIGINAL.md
Expand Up @@ -2,7 +2,6 @@
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
<!-- Try to link to an open issue for more information. -->


<!-- In addition to that please answer these questions: -->

**What kind of change does this PR introduce?**
Expand Down
39 changes: 19 additions & 20 deletions .github/dependabot.yml
@@ -1,22 +1,21 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 20
labels:
- dependencies
versioning-strategy: widen
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 20
labels:
- dependencies
versioning-strategy: widen
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 20
labels:
- dependencies
versioning-strategy: widen
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 20
labels:
- dependencies
26 changes: 21 additions & 5 deletions .prettierignore
@@ -1,14 +1,30 @@
package.json

# Ignore test fixtures
test/*.*
# Ignore some test files
test/**/*.*
!test/*.js
!test/**/webpack.config.js
!test/**/test.config.js
!test/**/test.filter.js
!test/**/errors.js
!test/**/warnings.js
!test/**/deprecations.js
!test/*.md
!test/helpers/*.*

# Ignore example fixtures
examples/*.*
!examples/**/webpack.config.js
# Ignore some folders
benchmark/
coverage/

# Ignore generated files
*.check.js

# Ignore not supported files
*.d.ts

# Ignore precompiled schemas
schemas/**/*.check.js

# Ignore example fixtures
examples/
!examples/**/webpack.config.js
4 changes: 1 addition & 3 deletions assembly/tsconfig.json
@@ -1,6 +1,4 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": [
"./**/*.asm.ts"
]
"include": ["./**/*.asm.ts"]
}
15 changes: 7 additions & 8 deletions package.json
Expand Up @@ -150,7 +150,7 @@
"pretest": "yarn lint",
"prelint": "yarn setup",
"lint": "yarn code-lint && yarn special-lint && yarn type-lint && yarn typings-test && yarn module-typings-test && yarn yarn-lint && yarn pretty-lint && yarn spellcheck",
"code-lint": "eslint . --ext '.js' --cache",
"code-lint": "eslint --cache .",
"type-lint": "tsc",
"typings-test": "tsc -p tsconfig.types.test.json",
"module-typings-test": "tsc -p tsconfig.module.test.json",
Expand All @@ -159,9 +159,8 @@
"special-lint-fix": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/format-schemas --write && node tooling/generate-runtime-code.js --write && node tooling/generate-wasm-code.js --write && node node_modules/tooling/format-file-header --write && node node_modules/tooling/compile-to-definitions --write && node node_modules/tooling/precompile-schemas --write && node node_modules/tooling/generate-types --no-template-literals --write",
"fix": "yarn code-lint --fix && yarn special-lint-fix && yarn pretty-lint-fix",
"prepare": "husky install",
"pretty-lint-base": "prettier \"*.{ts,json,yml,yaml,md}\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.json\" \"examples/*.md\"",
"pretty-lint-base-all": "yarn pretty-lint-base \"*.js\" \"{setup,lib,bin,hot,benchmark,tooling,schemas}/**/*.js\" \"module.d.ts\" \"test/*.js\" \"test/helpers/*.js\" \"test/{configCases,watchCases,statsCases,hotCases,benchmarkCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"",
"pretty-lint-fix": "yarn pretty-lint-base-all --loglevel warn --write",
"pretty-lint-base": "prettier --cache .",
"pretty-lint-fix": "yarn pretty-lint-base --loglevel warn --write",
"pretty-lint": "yarn pretty-lint-base --check",
"yarn-lint": "yarn-deduplicate --fail --list -s highest yarn.lock",
"yarn-lint-fix": "yarn-deduplicate -s highest yarn.lock",
Expand All @@ -179,11 +178,11 @@
"cover:report": "nyc report -t coverage"
},
"lint-staged": {
"*.js|{lib,setup,bin,hot,tooling,schemas}/**/*.js|test/*.js|{test,examples}/**/webpack.config.js}": [
"eslint --cache"
"*.{js,cjs,mjs}": [
"eslint --cache --fix"
],
"*.{ts,json,yml,yaml,md}|examples/*.md": [
"prettier --check"
"*": [
"prettier --cache --ignore-unknown"
],
"*.md|{.github,benchmark,bin,examples,hot,lib,schemas,setup,tooling}/**/*.{md,yml,yaml,js,json}": [
"cspell"
Expand Down
29 changes: 21 additions & 8 deletions test/README.md
@@ -1,49 +1,60 @@
# Welcome to the webpack test suite!!!!

Every pull request that you submit to webpack (besides README and spelling corrections in comments) requires tests that are created.

But don't give up hope!!! Although our tests may appear complex and overwhelming, once you become familiar with the test suite and structure, adding and creating tests will be fun and beneficial as you work inside the codebase! ❤

## tl;dr

Run all tests (this automatically runs the setup):

```sh
yarn test
```

Run an individual suite:

```sh
yarn jest ConfigTestCases
```

Watch mode:

```sh
yarn jest --watch ConfigTestCases
```

See also: [Jest CLI docs](https://jestjs.io/docs/cli)

## Test suite overview

We use Jest for our tests. For more information on Jest you can visit their [homepage](https://jestjs.io/)!

### Class Tests
All test files can be found in *.test.js. There are many tests that simply test APIs of a specific class/file (such as `Compiler`, `Errors`, Integration, `Parser`, `RuleSet`, Validation).

All test files can be found in \*.test.js. There are many tests that simply test APIs of a specific class/file (such as `Compiler`, `Errors`, Integration, `Parser`, `RuleSet`, Validation).
If the feature you are contributing involves one of those classes, then best to start there to understand the structure.

### xCases
In addition to Class specific tests, there are also directories that end in "Cases". The suites for these cases also have corresponding *.test.js files.

In addition to Class specific tests, there are also directories that end in "Cases". The suites for these cases also have corresponding \*.test.js files.

#### cases (`TestCases.test.js`) <sup>1</sup>

Cases are a set of general purpose tests that will run against a variety of permutations of webpack configurations. When you are making a general purpose change that doesn't require you to have a special configuration, you would likely add your tests here. Inside of the `./test/cases` directory you will find tests are broken into thematic sub directories. Take a moment to explore the different options.

To add a new case, create a new directory inside of the top level test groups, and then add an `index.js` file (and any other supporting files).

By default this file will be the entry point for the test suite and you can add your `it()`'s there. This will also become bundled so that node env support happens as well.

#### configCases (`ConfigTestCases.basictest.js`) <sup>1</sup>

If you are trying to solve a bug which is reproducible when x and y properties are used together in a config, then configCases is the place to be!!!!

In addition to an `index.js`, these configCases require a `webpack.config.js` is located inside of your test suite. This will run this specific config through `webpack` just as you were building individually. They will use the same loading/bundling technique of your `it()` tests, however you now have a more specific config use cases that you can write even before you start coding.

#### statsCases (`StatsTestCases.basictest.js`)

Stats cases are similar to configCases except specifically focusing on the `expected` output of your stats. Instead of writing to the console, however the output of stats will be written to disk.

By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run, runner is checking output using jest's awesome snapshot functionality.
Expand All @@ -52,21 +63,23 @@ Basically you don't need to write any expected behaviors yourself. The assumptio

Please follow the approach described below:

* write your test code in `statsCases/` folder by creating a separate folder for it, for example `statsCases/some-file-import-stats/index.js`
- write your test code in `statsCases/` folder by creating a separate folder for it, for example `statsCases/some-file-import-stats/index.js`

```javascript
import("./someModule");
```
* don't forget the `webpack.config.js`
* run the test
* jest will automatically add the output from your test code to `StatsTestCases.test.js.snap` and you can always check your results there
* Next time test will run -> runner will compare results against your output written to snapshot previously

- don't forget the `webpack.config.js`
- run the test
- jest will automatically add the output from your test code to `StatsTestCases.test.js.snap` and you can always check your results there
- Next time test will run -> runner will compare results against your output written to snapshot previously

You can read more about SnapShot testing [right here](https://jestjs.io/docs/snapshot-testing)

## Questions? Comments?
If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on!

If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on!

## Footnotes

<sup>1</sup> webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow Node.js' timeline for dropping older versions of node. Because of this we expect your tests on GitHub Actions to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions.
2 changes: 1 addition & 1 deletion test/cases/chunks/runtime/test.filter.js
@@ -1,4 +1,4 @@
module.exports = function(config) {
module.exports = function (config) {
// This test can't run in development mode as it depends on the flagIncludedChunks optimization
return config.mode !== "development";
};
4 changes: 3 additions & 1 deletion test/cases/chunks/weird-reference-to-entry/errors.js
@@ -1,3 +1,5 @@
module.exports = [
[/It's not allowed to load an initial chunk on demand\. The chunk name "main" is already used by an entrypoint\./],
[
/It's not allowed to load an initial chunk on demand\. The chunk name "main" is already used by an entrypoint\./
]
];
5 changes: 1 addition & 4 deletions test/cases/compile/error-hide-stack/errors.js
@@ -1,6 +1,3 @@
module.exports = [
[
/Module build failed( \(from [^)]+\))?:\nMessage/,
{details: /Stack/}
]
[/Module build failed( \(from [^)]+\))?:\nMessage/, { details: /Stack/ }]
];
2 changes: 1 addition & 1 deletion test/cases/context/issue-5750/warnings.js
@@ -1,3 +1,3 @@
module.exports = [
[/Critical dependency: Contexts can't use RegExps with the 'g' or 'y' flags/],
[/Critical dependency: Contexts can't use RegExps with the 'g' or 'y' flags/]
];
2 changes: 1 addition & 1 deletion test/cases/errors/case-sensitive/test.filter.js
@@ -1,6 +1,6 @@
var fs = require("fs");
var path = require("path");

module.exports = function(config) {
module.exports = function (config) {
return fs.existsSync(path.join(__dirname, "TEST.FILTER.JS"));
};
12 changes: 10 additions & 2 deletions test/cases/errors/case-sensitive/warnings.js
@@ -1,4 +1,12 @@
module.exports = [
[/There are multiple modules with names that only differ in casing/, /case-sensitive.A\.js/, /case-sensitive.a\.js/],
[/There are multiple modules with names that only differ in casing/, /case-sensitive.B.file\.js/, /case-sensitive.b.file\.js/]
[
/There are multiple modules with names that only differ in casing/,
/case-sensitive.A\.js/,
/case-sensitive.a\.js/
],
[
/There are multiple modules with names that only differ in casing/,
/case-sensitive.B.file\.js/,
/case-sensitive.b.file\.js/
]
];
4 changes: 1 addition & 3 deletions test/cases/errors/crash-missing-import/errors.js
@@ -1,3 +1 @@
module.exports = [
[/Module not found/],
];
module.exports = [[/Module not found/]];

0 comments on commit 5579b56

Please sign in to comment.