question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Process not defined when parsing threshold config

See original GitHub issue

Describe a bug

My jest.config.js looks like this:

const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

require('jest-preset-angular/ngcc-jest-processor');

// Deliberately set to not UTC.
process.env.TZ = 'Europe/Kiev';

module.exports = {
  preset: 'jest-preset-angular',
  ...
};

When I add jest-coverage-report-action to my workflow, I get

Warning:  Failed to parse jest configuration. "coverageThreshold" from config file will be ignored. evalmachine.<anonymous>:7
process.env.TZ = 'Europe/Kiev';
^
ReferenceError: process is not defined
    at evalmachine.<anonymous>:7:1
    at Script.runInContext (node:vm:139:12)
    at evaluateCjsModule (/home/runner/work/_actions/ArtiomTr/jest-coverage-report-action/v2/dist/index.js:23:5853)

even though I am setting up node prior to this:

 - uses: actions/setup-node@v2
        with:
          node-version: '16'
          cache: 'yarn'

and I don’t get this error in my previous test setup, so the issue is specific to parsing jest config by report action.

Details

https://github.com/truenas/webui/pull/6505 https://github.com/truenas/webui/runs/5512126744?check_suite_focus=true

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ArtiomTrcommented, Mar 14, 2022

Hey @therynamo 👋,

The cfgn is a small abstraction over configuration parsing. It resolves .js, .mjs, .cjs, .ts and .json configurations - all of these extensions should be supported by this action, because jest supports them (link). require.actual will not evaluate configuration correctly, for several reasons:

  1. Action is compiled in commonjs format, to support older node versions. The es module could not be “required” from commonjs - import should be used instead.
  2. There is no support for importing json files from es modules in node, it is still experimental. This means that if this action will be moved to es-modules, this might cause some issues.
  3. Node does not support typescript.

Plus, all logic with resolving these configurations and other stuff. So, I decided to put all this logic in a separate package to make it easier to maintain.

Also, I can’t use the jest-config package because it couldn’t be bundled. This means, that with jest-config package, action would need to run separate installation step before each run, what will decrease performance.

I agree that cfgn should inject node globals, and that the current behavior is a bug. I don’t have much time to maintain this action, but I will try to fix this issue as soon as possible.

1reaction
ArtiomTrcommented, Mar 14, 2022

Hello @undsoft 👋,

To parse jest configuration, action evaluates your configuration in environment, with no node globals. You can easily avoid this issue by simply importing “process” module:

const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');
+ const process = require('node:process');

require('jest-preset-angular/ngcc-jest-processor');

// Deliberately set to not UTC.
process.env.TZ = 'Europe/Kiev';

module.exports = {
  preset: 'jest-preset-angular',
  ...
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: process is not defined - Stack Overflow
I got xk6-dotenv working only by building a custom k6 binary... Is building a custom k6 binary the only way to utilize the...
Read more >
Parse and validate thresholds before starting the execution
Problem statement We would like to parse and validate threshold expressions at the end of the init context's evaluation, in order to have ......
Read more >
Process | Node.js v19.3.0 Documentation
The message goes through serialization and parsing. The resulting message might not be the same as what is originally sent. If the serialization...
Read more >
Resolve validation errors - Azure DevOps Services
Missing closing tags, missing quotes, missing open or close brackets (< or >) can cause a parsing file error. From the error message,...
Read more >
Gst-nvinfer — DeepStream 6.1.1 Release documentation
Property Meaning Network Types. / Applic... num‑detected‑classes Number of classes detected by the network Detector. Both tensor‑meta‑pool‑size Size of the output tensor meta pool All....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found