generated from hbenl/vscode-example-test-adapter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f281511
commit 8c37221
Showing
15 changed files
with
2,700 additions
and
651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
out/ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ package-lock.json | |
tsconfig.json | ||
.vscode/** | ||
.gitignore | ||
!node_modules/jest-editor-support |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": { | ||
|
@@ -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" | ||
|
@@ -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", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.