Skip to content

Commit

Permalink
Merge pull request #392 from atls/sync/yarn-plugin-test
Browse files Browse the repository at this point in the history
sync(yarn-plugin-test): dependencies, abstract command
  • Loading branch information
Nelfimov authored Aug 21, 2024
2 parents 9ac10ce + b01fc8e commit d086abd
Show file tree
Hide file tree
Showing 9 changed files with 809 additions and 760 deletions.
294 changes: 151 additions & 143 deletions .pnp.cjs

Large diffs are not rendered by default.

1,114 changes: 558 additions & 556 deletions .yarn/releases/yarn.cjs

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1343,15 +1343,19 @@ __metadata:
version: 0.0.0-use.local
resolution: "@atls/yarn-plugin-test@workspace:yarn/plugin-test"
dependencies:
"@atls/cli-ui-log-record-component": "workspace:*"
"@atls/cli-ui-renderer": "workspace:*"
"@atls/code-test-worker": "workspace:*"
"@atls/yarn-test-utils": "workspace:*"
"@jest/globals": "npm:29.7.0"
"@yarnpkg/builder": "npm:4.1.1"
"@yarnpkg/cli": "npm:4.2.2"
"@yarnpkg/core": "npm:4.0.5"
"@types/react": "npm:18.3.3"
"@yarnpkg/builder": "npm:4.1.2"
"@yarnpkg/cli": "npm:4.4.0"
"@yarnpkg/core": "npm:4.1.2"
"@yarnpkg/fslib": "npm:3.1.0"
clipanion: "npm:4.0.0-rc.3"
typescript: "npm:5.2.2"
react: "npm:18.3.1"
typescript: "npm:5.4.2"
peerDependencies:
"@yarnpkg/cli": "*"
"@yarnpkg/core": "*"
Expand Down
9 changes: 0 additions & 9 deletions yarn/plugin-test/bundles/@yarnpkg/plugin-test.js

This file was deleted.

24 changes: 18 additions & 6 deletions yarn/plugin-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,37 @@
"postpack": "rm -rf dist"
},
"dependencies": {
"@atls/cli-ui-log-record-component": "workspace:*",
"@atls/cli-ui-renderer": "workspace:*",
"@atls/code-test-worker": "workspace:*",
"clipanion": "4.0.0-rc.3"
"clipanion": "4.0.0-rc.3",
"react": "18.3.1"
},
"devDependencies": {
"@atls/yarn-test-utils": "workspace:*",
"@jest/globals": "29.7.0",
"@yarnpkg/builder": "4.1.1",
"@yarnpkg/cli": "4.2.2",
"@yarnpkg/core": "4.0.5",
"@types/react": "18.3.3",
"@yarnpkg/builder": "4.1.2",
"@yarnpkg/cli": "4.4.0",
"@yarnpkg/core": "4.1.2",
"@yarnpkg/fslib": "3.1.0",
"typescript": "5.2.2"
"typescript": "5.4.2"
},
"peerDependencies": {
"@yarnpkg/cli": "*",
"@yarnpkg/core": "*"
},
"publishConfig": {
"access": "public",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"main": "dist/index.js",
"typings": "dist/index.d.ts"
"types": "dist/index.d.ts"
}
}
49 changes: 49 additions & 0 deletions yarn/plugin-test/sources/abstract-test.command.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { BaseCommand } from '@yarnpkg/cli'
import { Option } from 'clipanion'
import React from 'react'

import { LogRecord } from '@atls/cli-ui-log-record-component'
import { renderStatic } from '@atls/cli-ui-renderer'

export abstract class AbstractTestCommand extends BaseCommand {
bail = Option.Boolean('-b,--bail', false)

updateSnapshot = Option.Boolean('-u,--update-shapshot', false)

findRelatedTests = Option.Boolean('--find-related-tests', false)

watchMode = Option.Boolean('--watch')

watchAllMode = Option.Boolean('--watchAll')

files: Array<string> = Option.Rest({ required: 0 })

wrapOutput(): void {
const original = process.stdout.write

process.stdout.write = (value: Uint8Array | string, ...rest: Array<any>): boolean => {
const items: Array<string> = value.toString().split('\n')

const logRecords: Array<string> = items.map((item) => {
try {
const logRecord = JSON.parse(item)

if ('severityText' in logRecord) {
return `${renderStatic(<LogRecord {...logRecord} />)}\n`
}

return item
} catch {
return item
}
})

logRecords.forEach((logRecord) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
original.bind(process.stdout)(logRecord, ...rest)
})

return true
}
}
}
1 change: 1 addition & 0 deletions yarn/plugin-test/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { plugin as default } from './test.plugin.js'

export * from './test-integration.command.js'
export * from './test-unit.command.js'
export * from './abstract-test.command.jsx'
32 changes: 11 additions & 21 deletions yarn/plugin-test/sources/test-integration.command.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import { join } from 'node:path'
import { join } from 'node:path'

import { BaseCommand } from '@yarnpkg/cli'
import { StreamReport } from '@yarnpkg/core'
import { Configuration } from '@yarnpkg/core'
import { Project } from '@yarnpkg/core'
import { Option } from 'clipanion'
import { StreamReport } from '@yarnpkg/core'
import { Configuration } from '@yarnpkg/core'
import { Project } from '@yarnpkg/core'

import { TesterWorker } from '@atls/code-test-worker'
import { TesterWorker } from '@atls/code-test-worker'

class TestIntegrationCommand extends BaseCommand {
static paths = [['test', 'integration']]

bail = Option.Boolean('-b,--bail', false)

updateSnapshot = Option.Boolean('-u,--update-shapshot', false)

findRelatedTests = Option.Boolean('--find-related-tests', false)
import { AbstractTestCommand } from './abstract-test.command.jsx'

watchMode = Option.Boolean('--watch')

watchAllMode = Option.Boolean('--watchAll')

files: Array<string> = Option.Rest({ required: 0 })
class TestIntegrationCommand extends AbstractTestCommand {
static paths = [['test', 'integration']]

async execute() {
async execute(): Promise<number> {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins)
const { project, workspace } = await Project.find(configuration, this.context.cwd)

Expand All @@ -50,6 +38,8 @@ class TestIntegrationCommand extends BaseCommand {
configuration,
},
async () => {
this.wrapOutput()

await new TesterWorker(project.cwd).run(
this.context.cwd,
'integration',
Expand Down
34 changes: 13 additions & 21 deletions yarn/plugin-test/sources/test-unit.command.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import { join } from 'node:path'
import { join } from 'node:path'

import { BaseCommand } from '@yarnpkg/cli'
import { StreamReport } from '@yarnpkg/core'
import { Configuration } from '@yarnpkg/core'
import { Project } from '@yarnpkg/core'
import { Option } from 'clipanion'
import { BaseCommand } from '@yarnpkg/cli'
import { StreamReport } from '@yarnpkg/core'
import { Configuration } from '@yarnpkg/core'
import { Project } from '@yarnpkg/core'
import { Option } from 'clipanion'

import { TesterWorker } from '@atls/code-test-worker'
import { TesterWorker } from '@atls/code-test-worker'

class TestUnitCommand extends BaseCommand {
static paths = [['test', 'unit']]

bail = Option.Boolean('-b,--bail', false)

updateSnapshot = Option.Boolean('-u,--update-shapshot', false)

findRelatedTests = Option.Boolean('--find-related-tests', false)
import { AbstractTestCommand } from './abstract-test.command.jsx'

watchMode = Option.Boolean('--watch')

watchAllMode = Option.Boolean('--watchAll')

files: Array<string> = Option.Rest({ required: 0 })
class TestUnitCommand extends AbstractTestCommand {
static paths = [['test', 'unit']]

async execute() {
async execute(): Promise<number> {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins)
const { project, workspace } = await Project.find(configuration, this.context.cwd)

Expand All @@ -50,6 +40,8 @@ class TestUnitCommand extends BaseCommand {
configuration,
},
async () => {
this.wrapOutput()

await new TesterWorker(project.cwd).run(
this.context.cwd,
'unit',
Expand Down

0 comments on commit d086abd

Please sign in to comment.