test: compute list of expected globals from ESLint config file#42056
test: compute list of expected globals from ESLint config file#42056aduh95 wants to merge 15 commits intonodejs:mainfrom
Conversation
test/common/index.js
Outdated
| atob, | ||
| btoa | ||
| } = require('buffer'); | ||
| const parseEslintConfigForGlobals = require('./parseEslintConfigForGlobals'); |
There was a problem hiding this comment.
Does this need to be a separate file? Should it be inlined so that people don't think it's something they can/should include themselves in their own tests?
RaisinTen
left a comment
There was a problem hiding this comment.
We need to synchronously read and parse lib/.eslintrc.yaml line-by-line for this to work correctly.
b3964c2 to
d6e4f2d
Compare
d6e4f2d to
96115e9
Compare
96115e9 to
9a5ec5f
Compare
Makefile
Outdated
|
|
||
| .PHONY: jstest | ||
| jstest: build-addons build-js-native-api-tests build-node-api-tests ## Runs addon tests and JS tests | ||
| jstest: build-addons build-js-native-api-tests build-node-api-tests test/common/knownGlobals.json ## Runs addon tests and JS tests |
Makefile
Outdated
| ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).pkg.done" | ||
|
|
||
| $(TARBALL): release-only doc-only | ||
| $(TARBALL): release-only doc-only test/common/knownGlobals.json |
There was a problem hiding this comment.
This target will also probably need to copy in the generated test/common/knownGlobals.json as the tarball is prepared in $(TARNAME)/ from a fresh git checkout-index.
|
Blocked on nodejs/build#2879 |
|
What's the reason for using Python to generate the file? |
Because the tarball action doesn't have any available |
|
Don't GitHub runners all have |
Maybe it was too old to work? I don't exactly remember tbh. Using Python as also the upside of being already integrated in the test suite. Is there a reason not to use Python? |
I hope that one day, Python won't be required anymore to work on node, so adding things that rely on it doesn't help. |
|
OK gotcha! Hopefully this won't be too much of a burden to port this to whatever replacement we find – it could be a sed script if it wasn't for Windows support. |
| const tmpdir = require('../common/tmpdir'); | ||
| tmpdir.refresh(); | ||
|
|
||
| common.allowGlobals('require', '_', '_error', ...require('module').builtinModules); |
There was a problem hiding this comment.
Maybe add common.allowReplGlobals() or similar to avoid repetition?
|
I'm ok with the bullet points in your OP, and the changes to |
If we avoid Python and generate the JSON in JS, it would be convenient to do it without creating any additional files which would address #42056 (comment) but I don't know how much time it would add overall when we run all the tests. |
We don't want to rely on mutable globals for core modules. Instead of
maintaining a separate list of known globals in our test files, parse
the ESLint config to ensure all globals are restricted in the
lib/directory.
fetch). It also solves the case where there are two global variables referencing the same object (e.g.globalandglobalThis).@targos This may have consequences for V8 updates (if the new V8 version ships with new globals).
/cc @benjamingr
Blocked on
#42049nodejs/build#2879.