-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-test-runner): add initial plugin
- Loading branch information
robby rabbitman
committed
Jun 29, 2024
1 parent
6c9f512
commit cfb0219
Showing
22 changed files
with
2,296 additions
and
234 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,47 @@ | ||
{ | ||
"root": true, | ||
"ignorePatterns": ["**/*"], | ||
"plugins": ["@nx"], | ||
"overrides": [ | ||
{ | ||
"files": "*.json", | ||
"parser": "jsonc-eslint-parser", | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": { | ||
"@nx/enforce-module-boundaries": [ | ||
"error", | ||
{ | ||
"enforceBuildableLibDependency": true, | ||
"allow": [], | ||
"depConstraints": [ | ||
{ | ||
"sourceTag": "*", | ||
"onlyDependOnLibsWithTags": ["*"] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"extends": ["plugin:@nx/typescript"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"extends": ["plugin:@nx/javascript"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"], | ||
"env": { | ||
"jest": true | ||
}, | ||
"rules": {} | ||
} | ||
] | ||
} |
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,5 @@ | ||
# Add files here to ignore them from prettier formatting | ||
/dist | ||
/coverage | ||
/.nx/cache | ||
/.nx/workspace-data |
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,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
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,3 +1,7 @@ | ||
{ | ||
"recommendations": ["nrwl.angular-console", "esbenp.prettier-vscode"] | ||
"recommendations": [ | ||
"nrwl.angular-console", | ||
"esbenp.prettier-vscode", | ||
"firsttris.vscode-jest-runner" | ||
] | ||
} |
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,3 @@ | ||
{ | ||
"eslint.validate": ["json"] | ||
} |
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,5 @@ | ||
import { getJestProjectsAsync } from '@nx/jest'; | ||
|
||
export default async () => ({ | ||
projects: await getJestProjectsAsync(), | ||
}); |
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,3 @@ | ||
const nxPreset = require('@nx/jest/preset').default; | ||
|
||
module.exports = { ...nxPreset }; |
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,24 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
}, | ||
{ | ||
"files": ["./package.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/nx-plugin-checks": "error" | ||
} | ||
} | ||
] | ||
} |
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 @@ | ||
# web-test-runner |
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,10 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'web-test-runner', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/libs/web-test-runner', | ||
}; |
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,15 @@ | ||
{ | ||
"name": "@robby-rabbitman/web-test-runner", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"tslib": "^2.3.0", | ||
"@nx/devkit": "19.3.2" | ||
}, | ||
"type": "commonjs", | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts", | ||
"exports": { | ||
".": "./src/index.js", | ||
"./plugin": "./src/plugin.js" | ||
} | ||
} |
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,39 @@ | ||
{ | ||
"name": "web-test-runner", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"tags": ["scope:node", "type:plugin"], | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/{projectRoot}", | ||
"main": "{projectRoot}/src/index.ts", | ||
"tsConfig": "{projectRoot}/tsconfig.lib.json", | ||
"assets": [ | ||
"{projectRoot}/*.md", | ||
{ | ||
"input": "{projectRoot}/src", | ||
"glob": "**/!(*.ts)", | ||
"output": "./src" | ||
}, | ||
{ | ||
"input": "{projectRoot}/src", | ||
"glob": "**/*.d.ts", | ||
"output": "./src" | ||
}, | ||
{ | ||
"input": "{projectRoot}", | ||
"glob": "generators.json", | ||
"output": "." | ||
}, | ||
{ | ||
"input": "{projectRoot}", | ||
"glob": "executors.json", | ||
"output": "." | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
export default {}; |
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,78 @@ | ||
import { | ||
CreateNodesFunction, | ||
CreateNodesV2, | ||
createNodesFromFiles, | ||
getPackageManagerCommand, | ||
} from '@nx/devkit'; | ||
import { existsSync } from 'node:fs'; | ||
import { dirname, join } from 'node:path'; | ||
|
||
type WebTestRunnerTargetPluginOptions = { targetName: string }; | ||
|
||
const webTestRunnerConfigFileNameGlob = '**/wtr.config.@(js|cjs|mjs)'; | ||
|
||
const packageManagerCommand = getPackageManagerCommand(); | ||
|
||
const defaultTargetName = 'test'; | ||
|
||
/** | ||
* In `targets` in a `project.json`, nx replaces this symbol with the relative path to the project from the workspace root. | ||
*/ | ||
const projectRootSymbol = '{projectRoot}'; | ||
|
||
export const createNodesV2: CreateNodesV2<WebTestRunnerTargetPluginOptions> = [ | ||
webTestRunnerConfigFileNameGlob, | ||
(webTestRunnerConfigFileNames, options, context) => { | ||
return createNodesFromFiles( | ||
createWebTestRunnerTarget, | ||
webTestRunnerConfigFileNames, | ||
options, | ||
context | ||
); | ||
}, | ||
]; | ||
|
||
const createWebTestRunnerTarget: CreateNodesFunction = ( | ||
webTestRunnerConfigFileName: string, | ||
options: WebTestRunnerTargetPluginOptions | ||
) => { | ||
const webTestRunnerConfigDirectory = dirname(webTestRunnerConfigFileName); | ||
|
||
const isWebTestRunnerConfigInProject = isProject( | ||
webTestRunnerConfigDirectory | ||
); | ||
|
||
// make sure the config is in a project: a user may have a shared config located e.g. in the root of the workspace which matches the `wtrConfigFileNameRegEx` | ||
if (!isWebTestRunnerConfigInProject) { | ||
return {}; | ||
} | ||
|
||
const targetName = options?.targetName ?? defaultTargetName; | ||
|
||
return { | ||
projects: { | ||
[webTestRunnerConfigDirectory]: { | ||
targets: { | ||
[targetName]: { | ||
command: `${packageManagerCommand.exec} wtr --config=${webTestRunnerConfigFileNameGlob}`, | ||
options: { | ||
cwd: `${projectRootSymbol}`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
/** | ||
* | ||
* @param directory | ||
* @returns whether the directory is considered a nx project. | ||
*/ | ||
const isProject = (directory: string) => { | ||
return ( | ||
existsSync(join(directory, 'project.json')) || | ||
existsSync(join(directory, 'package.json')) | ||
); | ||
}; |
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,17 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"types": ["node"] | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
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,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": true | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts"] | ||
} |
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,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
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
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 |
---|---|---|
|
@@ -7,9 +7,33 @@ | |
"packageManager": "[email protected]", | ||
"scripts": {}, | ||
"devDependencies": { | ||
"@nx/eslint": "19.3.2", | ||
"@nx/eslint-plugin": "19.3.2", | ||
"@nx/jest": "19.3.2", | ||
"@nx/js": "19.3.2", | ||
"@nx/plugin": "19.3.2", | ||
"@nx/workspace": "19.3.2", | ||
"nx": "19.3.2" | ||
"@swc-node/register": "~1.9.1", | ||
"@swc/cli": "~0.3.12", | ||
"@swc/core": "~1.5.7", | ||
"@swc/helpers": "~0.5.11", | ||
"@types/jest": "^29.4.0", | ||
"@types/node": "18.16.9", | ||
"@typescript-eslint/eslint-plugin": "^7.3.0", | ||
"@typescript-eslint/parser": "^7.3.0", | ||
"eslint": "~8.57.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"jest": "^29.4.1", | ||
"jest-environment-jsdom": "^29.4.1", | ||
"jest-environment-node": "^29.4.1", | ||
"nx": "19.3.2", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^29.1.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "~5.4.2" | ||
}, | ||
"dependencies": { | ||
"@nx/devkit": "19.3.2", | ||
"tslib": "^2.3.0" | ||
} | ||
} |
Oops, something went wrong.