Skip to content

Commit

Permalink
[node] Add process module definitions (#4491)
Browse files Browse the repository at this point in the history
* add node process definition

* fix node process tests
  • Loading branch information
Brianzchen committed Aug 13, 2023
1 parent 0419157 commit 10ad367
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions definitions/environments/node/flow_v0.155.x-/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ declare module 'fs/promises' {
declare module.exports: $Exports<'fs'>['promises'];
}

declare module 'process' {
declare module.exports: Process;
}

declare module 'node:process' {
declare module.exports: $Exports<'process'>;
}

// https://nodejs.org/api/esm.html#node-imports

declare module 'node:events' {
Expand Down
30 changes: 30 additions & 0 deletions definitions/environments/node/flow_v0.155.x-/test_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import url from 'url';

import nodeEvents from 'node:events';
import fsPromises from 'fs/promises';
import importProcess from 'process';
import nodeProcess from 'node:process';
import nodeFs from 'node:fs';
import nodeFsPromises from 'node:fs/promises';
import nodeOs from 'node:os';
Expand All @@ -30,6 +32,34 @@ describe('node', () => {
});
});

/**
* Tested differently as process exports a class
*/
describe('process', () => {
it('should retrieve the corresponding Flow core types', () => {
const returnValue = process.cwd();
(importProcess.cwd(): typeof returnValue);
// $FlowExpectedError[incompatible-cast] does not match return type of process function
(importProcess.cwd(): number);
// $FlowExpectedError[extra-arg] does not match type of process function
(importProcess.cwd(''));
});
});

/**
* Tested differently as process exports a class
*/
describe('node:process', () => {
it('should retrieve the corresponding Flow core types', () => {
const returnValue = process.cwd();
(nodeProcess.cwd(): typeof returnValue);
// $FlowExpectedError[incompatible-cast] does not match return type of process function
(nodeProcess.cwd(): number);
// $FlowExpectedError[extra-arg] does not match type of process function
(nodeProcess.cwd(''));
});
});

describe('node:fs', () => {
it('should retrieve the corresponding Flow core types', () => {
(nodeFs.writeFile: typeof fs.writeFile);
Expand Down

0 comments on commit 10ad367

Please sign in to comment.