-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from jest from ts-jest to swc #2333
Changes from all commits
3848ed1
77ec46d
384e620
dfe4665
9581bc3
df875f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
"pseudoterminal", | ||
"rwlock", | ||
"sonarjs", | ||
"spyable", | ||
"stackframe", | ||
"subdir", | ||
"submodules", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import { Logger } from './logger' | ||
|
||
jest.mock('console', () => { | ||
const actualModule = jest.requireActual('console') | ||
return { | ||
__esModule: true, | ||
...actualModule | ||
} | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] Unfortunately we cannot pull out a helper from this boilerplate as the compiler behaves differently if |
||
|
||
describe('Logger', () => { | ||
describe('error', () => { | ||
it('should be able to write an error to the console', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { Readable } from 'stream' | |
import { Event, EventEmitter } from 'vscode' | ||
import { Disposable } from '@hediet/std/disposable' | ||
import execa from 'execa' | ||
import { Logger } from './common/logger' | ||
|
||
interface RunningProcess extends ChildProcess { | ||
all?: Readable | ||
|
@@ -59,16 +58,3 @@ export const executeProcess = async ( | |
const { stdout } = await createProcess(options) | ||
return stdout | ||
} | ||
|
||
const sendOutput = (process: Process) => | ||
process.all?.on('data', chunk => | ||
Logger.log(chunk.toString().replace(/(\r?\n)/g, '')) | ||
) | ||
|
||
export const createProcessWithOutput = (options: ProcessOptions) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] moving this removed the need for a spy which was breaking some tests. It is currently only used in a single place so was ok to move. |
||
const process = createProcess(options) | ||
|
||
sendOutput(process) | ||
|
||
return process | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,21 @@ import { join } from 'path' | |
import { getVenvBinPath } from './path' | ||
import { getProcessPlatform } from '../env' | ||
import { exists } from '../fileSystem' | ||
import { createProcessWithOutput } from '../processExecution' | ||
import { Logger } from '../common/logger' | ||
import { createProcess, Process, ProcessOptions } from '../processExecution' | ||
|
||
const sendOutput = (process: Process) => | ||
process.all?.on('data', chunk => | ||
Logger.log(chunk.toString().replace(/(\r?\n)/g, '')) | ||
) | ||
|
||
export const createProcessWithOutput = (options: ProcessOptions) => { | ||
const process = createProcess(options) | ||
|
||
sendOutput(process) | ||
|
||
return process | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we allowed to use this to do things like getting the ast from the project's Python files ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could definitely try. Take a look at https://github.com/microsoft/vscode-python/tree/main/src/client/languageServer to see what those guys do (outside of the closed source language server) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is that closed, btw? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💰 |
||
|
||
const installPackages = (cwd: string, pythonBin: string, ...args: string[]) => { | ||
return createProcessWithOutput({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,10 @@ module.exports = { | |
moduleNameMapper: { | ||
'\\.(scss|css|less)$': 'identity-obj-proxy' | ||
}, | ||
preset: 'ts-jest', | ||
setupFiles: ['jest-canvas-mock', '<rootDir>/setup-tests.js'], | ||
testEnvironment: 'node', | ||
testTimeout: 20000 | ||
testEnvironment: 'jsdom', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] Has to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we only have to set this here once and not have to add
for every file, that is very cool. |
||
testTimeout: 20000, | ||
transform: { | ||
'^.+\\.(t|j)sx?$': ['@swc/jest'] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { configureStore } from '@reduxjs/toolkit' | ||
import '@testing-library/jest-dom/extend-expect' | ||
import { | ||
|
@@ -30,10 +27,20 @@ import { DragEnterDirection } from '../../../shared/components/dragDrop/util' | |
import { plotsReducers } from '../../store' | ||
import { webviewInitialState } from '../webviewSlice' | ||
import { getThemeValue, hexToRGB, ThemeProperty } from '../../../util/styles' | ||
import * as EventCurrentTargetDistances from '../../../shared/components/dragDrop/currentTarget' | ||
|
||
const getHeaders = () => screen.getAllByRole('columnheader') | ||
|
||
jest.mock('../../../shared/api') | ||
jest.mock('../../../shared/components/dragDrop/currentTarget', () => { | ||
const actualModule = jest.requireActual( | ||
'../../../shared/components/dragDrop/currentTarget' | ||
) | ||
return { | ||
__esModule: true, | ||
...actualModule | ||
} | ||
}) | ||
|
||
const { postMessage } = vsCodeApi | ||
const mockPostMessage = jest.mocked(postMessage) | ||
|
@@ -496,7 +503,12 @@ describe('ComparisonTable', () => { | |
|
||
const [, firstRow, secondRow] = screen.getAllByRole('rowgroup') // First rowgroup is the thead | ||
|
||
dragAndDrop(secondRow, firstRow, DragEnterDirection.BOTTOM) | ||
dragAndDrop( | ||
secondRow, | ||
firstRow, | ||
DragEnterDirection.BOTTOM, | ||
EventCurrentTargetDistances | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [C] This is gross but I could not find any other way to successfully spy on a single call of
I had to do this in 4 places. |
||
) | ||
|
||
const [, newFirstRow, newSecondRow] = screen.getAllByRole('rowgroup') | ||
|
||
|
@@ -509,7 +521,12 @@ describe('ComparisonTable', () => { | |
|
||
const [, firstRow, secondRow] = screen.getAllByRole('rowgroup') // First rowgroup is the thead | ||
|
||
dragAndDrop(firstRow, secondRow, DragEnterDirection.BOTTOM) | ||
dragAndDrop( | ||
firstRow, | ||
secondRow, | ||
DragEnterDirection.BOTTOM, | ||
EventCurrentTargetDistances | ||
) | ||
|
||
const [, newFirstRow, newSecondRow] = screen.getAllByRole('rowgroup') | ||
|
||
|
@@ -535,7 +552,12 @@ describe('ComparisonTable', () => { | |
|
||
const [, firstRow, secondRow] = screen.getAllByRole('rowgroup') // First rowgroup is the thead | ||
|
||
dragEnter(firstRow, secondRow.id, DragEnterDirection.BOTTOM) | ||
dragEnter( | ||
firstRow, | ||
secondRow.id, | ||
DragEnterDirection.BOTTOM, | ||
EventCurrentTargetDistances | ||
) | ||
|
||
const dropTarget = screen.getAllByRole('rowgroup')[2] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2333 (comment)