Skip to content

Commit

Permalink
rewrite and cleanup and webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
smarschollek committed Aug 30, 2021
1 parent f281511 commit 8c37221
Show file tree
Hide file tree
Showing 15 changed files with 2,700 additions and 651 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
out/
dist
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ package-lock.json
tsconfig.json
.vscode/**
.gitignore
!node_modules/jest-editor-support
2,456 changes: 2,258 additions & 198 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "img/icon.png",
"author": "Stephan Marschollek <[email protected]>",
"publisher": "smarschollek",
"version": "0.0.9",
"version": "0.1.0",
"license": "MIT",
"homepage": "https://github.com/smarschollek/vscode-react-scripts-test-adapter",
"repository": {
Expand All @@ -23,27 +23,34 @@
"testing",
"react-scripts"
],
"main": "out/main.js",
"main": "dist/main.js",
"scripts": {
"clean": "rimraf out *.vsix",
"build": "tsc",
"watch": "tsc -w",
"rebuild": "npm run clean && npm run build",
"package": "vsce package",
"publish": "vsce publish"
"publish": "vsce publish",
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"test-compile": "tsc -p ./"
},
"dependencies": {
"anymatch": "^3.1.2",
"chokidar": "^3.5.2",
"jest-editor-support": "^28.2.0",
"rimraf": "^3.0.2",
"tslib": "^1.14.1",
"vscode-test-adapter-api": "^1.9.0",
"vscode-test-adapter-util": "^0.7.1"
},
"devDependencies": {
"@types/vscode": "~1.23.0",
"ts-loader": "^9.2.5",
"typescript": "^3.9.9",
"vsce": "^1.88.0"
"vsce": "^1.88.0",
"webpack": "^5.51.1",
"webpack-cli": "^4.8.0"
},
"engines": {
"vscode": "^1.23.0"
Expand Down Expand Up @@ -84,11 +91,6 @@
"type": "string",
"scope": "resource"
},
"reactScriptsTestAdapter.flattenList": {
"description": "removes file name entries from tree list",
"type": "boolean",
"scope": "resource"
},
"reactScriptsTestAdapter.debugOutput": {
"description": "Select the output from the Debug process.",
"default": "internalConsole",
Expand Down
28 changes: 0 additions & 28 deletions src/DecorationBuilder.ts

This file was deleted.

52 changes: 52 additions & 0 deletions src/FileParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { TestInfo, TestSuiteInfo } from "vscode-test-adapter-api";
import { DescribeBlock, ItBlock, parse, ParsedNode, ParsedNodeTypes } from "jest-editor-support";
import { Uri } from "vscode";

export default class FileParser {
public parse(file: Uri) : (TestSuiteInfo | TestInfo)[] {
const node = parse(file.fsPath)
return this.parseChildren(node.root.children)
}

private parseChildren (children?: ParsedNode[], fullName?: string) : (TestSuiteInfo | TestInfo)[] {
const result: (TestSuiteInfo | TestInfo)[] = []

if(children) {
for(const child of children) {

if(child.type === ParsedNodeTypes.describe) {
const node = child as DescribeBlock
result.push({
id: this.buildId(node.name, fullName),
label: node.name,
file: node.file,
line: node.start.line - 1,
type: 'suite',
children: this.parseChildren(node.children, this.buildId(node.name, fullName))
})
}

if(child.type === ParsedNodeTypes.it) {
const node = child as ItBlock
result.push({
id: this.buildId(node.name, fullName),
label: node.name,
file: node.file,
line: node.start.line - 1,
type: 'test'
})
}
}
}

return result;
}

private buildId(name: string, fullname?: string) : string {
if(fullname) {
return (fullname + ' ' + name).trim()
}

return name
}
}
53 changes: 53 additions & 0 deletions src/ProjectManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { RelativePattern, Uri, workspace as ws, WorkspaceFolder, Event, EventEmitter } from "vscode";
import { TestInfo, TestSuiteInfo } from "vscode-test-adapter-api";
import { Log } from "vscode-test-adapter-util";
import * as settings from "./settings";
import FileParser from './FileParser'

export default class ProjectManager {
private filesChanged: EventEmitter<void>
private parser: FileParser

get onFilesChanged(): Event<void> { return this.filesChanged.event; }

public constructor(public readonly workspace: WorkspaceFolder,private readonly log: Log) {
this.filesChanged = new EventEmitter<void>();
this.parser = new FileParser();

const pattern = new RelativePattern(
ws.getWorkspaceFolder(workspace.uri)!,
settings.getBaseGlob() + settings.getWatchGlob())

const watcher = ws.createFileSystemWatcher(pattern)

watcher.onDidChange((event: Uri) => {
this.log.info(`${event} changed`)
this.filesChanged.fire()
})
watcher.onDidCreate((event: Uri) => {
this.log.info(`${event} created`)
this.filesChanged.fire()
})
watcher.onDidDelete((event: Uri) => {
this.log.info(`${event} deleted`)
this.filesChanged.fire()
})
}

public async loadTestSuite () : Promise<TestSuiteInfo> {
const files = await ws.findFiles(settings.getBaseGlob() + settings.getTestGlob())

let testInfo: (TestSuiteInfo | TestInfo)[] = []

for(const file of files) {
testInfo = [...testInfo, ...this.parser.parse(file)]
}

return {
id: "root",
label: `root`,
type: "suite",
children: testInfo
}
}
}
113 changes: 0 additions & 113 deletions src/RunnerFactory.ts

This file was deleted.

Loading

0 comments on commit 8c37221

Please sign in to comment.