Skip to content

Commit

Permalink
Merge pull request #1515 from Automattic/remove/flow
Browse files Browse the repository at this point in the history
refactor: remove flow
  • Loading branch information
sjinks authored Oct 3, 2023
2 parents 49f51a0 + 4e98180 commit 4ccef58
Show file tree
Hide file tree
Showing 62 changed files with 142 additions and 2,415 deletions.
7 changes: 1 addition & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
"overrides": [
{
"files": [ "*.js" ],
"parser": "@babel/eslint-parser",
"plugins": [ "flowtype" ],
"extends": [ "plugin:flowtype/recommended" ],
"rules": {
"flowtype/generic-spacing": 0
}
"parser": "@babel/eslint-parser"
}
]
}
14 changes: 0 additions & 14 deletions .flowconfig

This file was deleted.

3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
matrix:
config:
- { name: Lint, tool: lint }
- { name: Flow, tool: flow }
- { name: type checker, tool: check-types }
- { name: Type Checker, tool: check-types }
steps:
- name: Check out the source code
uses: actions/checkout@v3
Expand Down
42 changes: 8 additions & 34 deletions __tests__/bin/vip-config-envvar-delete.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
// @flow

/**
* External dependencies
*/
import { describe, expect, it, jest, beforeEach } from '@jest/globals';
import type { Response } from 'node-fetch';

/**
* Internal dependencies
*/
import { deleteEnvVarCommand } from '../../src/bin/vip-config-envvar-delete';
import command from '../../src/lib/cli/command';
// $FlowExpectedError[cannot-resolve-module]
import { deleteEnvVar, validateNameWithMessage } from '../../src/lib/envvar/api';
// $FlowExpectedError[cannot-resolve-module]
import { cancel, confirm, promptForValue } from '../../src/lib/envvar/input';
// $FlowExpectedError[cannot-resolve-module]
import { trackEvent } from '../../src/lib/tracker';

function mockExit() {
Expand All @@ -25,14 +19,8 @@ function mockExit() {
jest.spyOn( console, 'log' ).mockImplementation( () => {} );
jest.spyOn( process, 'exit' ).mockImplementation( mockExit );

interface CommandMockType {
argv: () => CommandMockType;
examples: () => CommandMockType;
option: () => CommandMockType;
}

jest.mock( 'lib/cli/command', () => {
const commandMock: CommandMockType = {
const commandMock = {
argv: () => commandMock,
examples: () => commandMock,
option: () => commandMock,
Expand Down Expand Up @@ -71,24 +59,11 @@ describe( 'vip config envvar delete', () => {
} );
} );

const mockConfirm: JestMockFn< [ string ], Promise< boolean > > = ((confirm: any): JestMockFn<
[ string ],
Promise< boolean >
>);
const mockValidateNameWithMessage: JestMockFn< [ string ], boolean > =
((validateNameWithMessage: any): JestMockFn< [ string ], boolean >);
const mockPromptForValue: JestMockFn<
[ string, string ],
Promise< string >
> = ((promptForValue: any): JestMockFn< [ string, string ], Promise< string > >);
const mockDeleteEnvVar: JestMockFn<
[ number, number, string ],
Promise< void >
> = ((deleteEnvVar: any): JestMockFn< [ number, number, string ], Promise< void > >);
const mockTrackEvent: JestMockFn< [], Promise< Response > > = ((trackEvent: any): JestMockFn<
[],
Promise< Response >
>);
const mockConfirm = confirm;
const mockValidateNameWithMessage = validateNameWithMessage;
const mockPromptForValue = promptForValue;
const mockDeleteEnvVar = deleteEnvVar;
const mockTrackEvent = trackEvent;

describe( 'deleteEnvVarCommand', () => {
let args;
Expand All @@ -99,7 +74,7 @@ describe( 'deleteEnvVarCommand', () => {
const executeEvent = [ 'envvar_delete_command_execute', eventPayload ];
const successEvent = [ 'envvar_delete_command_success', eventPayload ];

function setFixtures( name: string, skipConfirmation: string = '' ) {
function setFixtures( name, skipConfirmation = '' ) {
args = [ name ];
opts = {
app: {
Expand Down Expand Up @@ -189,7 +164,6 @@ describe( 'deleteEnvVarCommand', () => {
await expect( () => deleteEnvVarCommand( args, opts ) ).rejects.toEqual( 'EXIT' );

expect( validateNameWithMessage ).toHaveBeenCalledWith( name );
// $FlowIgnore[method-unbinding] No idea how to fix this
expect( process.exit ).toHaveBeenCalledWith( 1 );

expect( promptForValue ).not.toHaveBeenCalled();
Expand All @@ -205,7 +179,7 @@ describe( 'deleteEnvVarCommand', () => {

setFixtures( name );
mockPromptForValue.mockImplementation( () => Promise.resolve( name ) );
mockDeleteEnvVar.mockImplementation( () => Promise.reject< void >( thrownError ) );
mockDeleteEnvVar.mockImplementation( () => Promise.reject( thrownError ) );

await expect( () => deleteEnvVarCommand( args, opts ) ).rejects.toEqual( thrownError );

Expand Down
54 changes: 14 additions & 40 deletions __tests__/bin/vip-config-envvar-set.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
// @flow

/**
* External dependencies
*/
import { describe, expect, it, jest } from '@jest/globals';
import type { Response } from 'node-fetch';

/**
* Internal dependencies
*/
import { setEnvVarCommand } from '../../src/bin/vip-config-envvar-set';
import command from '../../src/lib/cli/command';
// $FlowExpectedError[cannot-resolve-module]
import { setEnvVar, validateNameWithMessage } from '../../src/lib/envvar/api';
// $FlowExpectedError[cannot-resolve-module]
import { cancel, confirm, promptForValue } from '../../src/lib/envvar/input';
// $FlowExpectedError[cannot-resolve-module]
import { readVariableFromFile } from '../../src/lib/envvar/read-file';
// $FlowExpectedError[cannot-resolve-module]
import { trackEvent } from '../../src/lib/tracker';

function mockExit() {
Expand All @@ -27,14 +20,8 @@ function mockExit() {
jest.spyOn( console, 'log' ).mockImplementation( () => {} );
jest.spyOn( process, 'exit' ).mockImplementation( mockExit );

interface CommandMockType {
argv: () => CommandMockType;
examples: () => CommandMockType;
option: () => CommandMockType;
}

jest.mock( 'lib/cli/command', () => {
const commandMock: CommandMockType = {
const commandMock = {
argv: () => commandMock,
examples: () => commandMock,
option: () => commandMock,
Expand Down Expand Up @@ -71,28 +58,12 @@ jest.mock( '../../src/lib/tracker', () => ( {
trackEvent: jest.fn(),
} ) );

const mockConfirm: JestMockFn< [ string ], Promise< boolean > > = ((confirm: any): JestMockFn<
[ string ],
Promise< boolean >
>);
const mockValidateNameWithMessage: JestMockFn< [ string ], boolean > =
((validateNameWithMessage: any): JestMockFn< [ string ], boolean >);
const mockPromptForValue: JestMockFn<
[ string, string ],
Promise< string >
> = ((promptForValue: any): JestMockFn< [ string, string ], Promise< string > >);
const mockSetEnvVar: JestMockFn<
[ number, number, string, string ],
Promise< void >
> = ((setEnvVar: any): JestMockFn< [ number, number, string, string ], Promise< void > >);
const mockTrackEvent: JestMockFn< [], Promise< Response > > = ((trackEvent: any): JestMockFn<
[],
Promise< Response >
>);
const mockReadVariableFromFile: JestMockFn<
[ any ],
Promise< string >
> = ((readVariableFromFile: any): JestMockFn< [ any ], Promise< string > >);
const mockConfirm = confirm;
const mockValidateNameWithMessage = validateNameWithMessage;
const mockPromptForValue = promptForValue;
const mockSetEnvVar = setEnvVar;
const mockTrackEvent = trackEvent;
const mockReadVariableFromFile = readVariableFromFile;

describe( 'vip config envvar set', () => {
it( 'registers as a command', () => {
Expand All @@ -109,7 +80,12 @@ describe( 'setEnvVarCommand', () => {
const executeEvent = [ 'envvar_set_command_execute', eventPayload ];
const successEvent = [ 'envvar_set_command_success', eventPayload ];

function setFixtures( name: string, fromFile: string = '', skipConfirmation: string = '' ) {
/**
* @param {string} name
* @param {string} fromFile
* @param {string} skipConfirmation
*/
function setFixtures( name, fromFile = '', skipConfirmation = '' ) {
args = [ name ];
opts = {
app: {
Expand Down Expand Up @@ -137,7 +113,6 @@ describe( 'setEnvVarCommand', () => {

it( 'validates the name, prompts for confirmation, sets the variable, and prints success', async () => {
const name = 'TEST_VARIABLE';
// $FlowIgnore[method-unbinding] No idea how to fix this
const value = 'test value';

setFixtures( name );
Expand Down Expand Up @@ -227,7 +202,6 @@ describe( 'setEnvVarCommand', () => {
await expect( () => setEnvVarCommand( args, opts ) ).rejects.toEqual( 'EXIT' );

expect( validateNameWithMessage ).toHaveBeenCalledWith( name );
// $FlowIgnore[method-unbinding] No idea how to fix this
expect( process.exit ).toHaveBeenCalledWith( 1 );

expect( promptForValue ).not.toHaveBeenCalled();
Expand All @@ -245,7 +219,7 @@ describe( 'setEnvVarCommand', () => {

setFixtures( name );
mockPromptForValue.mockImplementation( () => Promise.resolve( value ) );
mockSetEnvVar.mockImplementation( () => Promise.reject< void >( thrownError ) );
mockSetEnvVar.mockImplementation( () => Promise.reject( thrownError ) );

await expect( () => setEnvVarCommand( args, opts ) ).rejects.toEqual( thrownError );

Expand Down
1 change: 0 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
presets: [
'@babel/preset-flow',
[
'@babel/preset-typescript',
{
Expand Down
Loading

0 comments on commit 4ccef58

Please sign in to comment.