-
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.
- Loading branch information
1 parent
855ad0b
commit 952f741
Showing
20 changed files
with
4,673 additions
and
0 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,5 @@ | ||
dist | ||
package.json | ||
./node_modules/ | ||
.vscode | ||
.idea |
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,50 @@ | ||
{ | ||
"root": true, | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"env": { | ||
"es6": true | ||
}, | ||
"plugins": ["simple-import-sort"], | ||
"overrides": [ | ||
{ | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"files": [ | ||
"lib/src/**/*.ts" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"rules": { | ||
"simple-import-sort/imports": "error", | ||
"simple-import-sort/exports": "error", | ||
"@typescript-eslint/ban-ts-comment": 0, | ||
"max-lines-per-function": [ | ||
1, | ||
{ | ||
"max": 40 | ||
} | ||
], | ||
"max-lines": [ | ||
1, | ||
{ | ||
"max": 150 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"files": [ | ||
"lib/src/**/*.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,33 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Setup Corepack | ||
run: | | ||
corepack enable | ||
corepack prepare [email protected] --activate | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run Semantic Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
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,2 @@ | ||
node_modules | ||
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"endOfLine": "auto", | ||
"printWidth": 100 | ||
} |
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,22 @@ | ||
/** | ||
* @type {import('semantic-release').GlobalConfig} | ||
*/ | ||
const releaseConfig = { | ||
branches: ["main"], | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
"@semantic-release/github", | ||
[ | ||
"@semantic-release/git", | ||
{ | ||
"assets": ["package.json", "CHANGELOG.md"], | ||
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" | ||
} | ||
] | ||
] | ||
}; | ||
|
||
module.exports = releaseConfig; |
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,136 @@ | ||
# Cypress Runner | ||
|
||
Cypress Runner is a command-line interface (CLI) tool designed to launch specified frontend and backend servers before running Cypress tests. The CLI expects to find a `.cypressrunnerrc` configuration file in the current working directory (cwd). | ||
|
||
## Installation | ||
|
||
To install Cypress Runner, you can use npm: | ||
|
||
```sh | ||
npm install -g @devmy/cypress-runner | ||
``` | ||
|
||
|
||
|
||
## Configuration | ||
|
||
Cypress Runner requires a `.cypressrunnerrc` file in the directory where it is executed. This file should export a configuration object that matches the interface [CypressRunnerConfig](lib/src/runner/cypress-runner-config.ts) | ||
|
||
|
||
### Example `.cypressrunnerrc` File | ||
|
||
```json | ||
{ | ||
"debug": true, | ||
"startWebServerCommands": [ | ||
{ "command": "npm run start:frontend", "name": "frontend" }, | ||
{ "command": "npm run start:backend", "name": "backend" } | ||
], | ||
"waitOn": { | ||
"resources": ["http://localhost:3000", "http://localhost:4000"], | ||
"delay": 1000, | ||
"timeout": 30000 | ||
} | ||
}; | ||
``` | ||
|
||
### Example `.cypressrunnerrc.json` File | ||
|
||
```json | ||
{ | ||
"debug": true, | ||
"startWebServerCommands": [ | ||
{ "command": "npm run start:frontend", "name": "frontend" }, | ||
{ "command": "npm run start:backend", "name": "backend" } | ||
], | ||
"waitOn": { | ||
"resources": ["http://localhost:3000", "http://localhost:4000"], | ||
"delay": 1000, | ||
"timeout": 30000 | ||
} | ||
}; | ||
``` | ||
|
||
### Example `.cypressrunnerrc.js` File | ||
|
||
```js | ||
/** @type import('@devmy/cypress-runner').CypressRunnerConfig*/ | ||
const config = { | ||
debug: true, | ||
startWebServerCommands: [ | ||
{ command: "npm run start:frontend", name: "frontend" }, | ||
{ command: "npm run start:backend", name: "backend" } | ||
], | ||
waitOn: { | ||
resources: ["http://localhost:3000", "http://localhost:4000"], | ||
delay: 1000, | ||
timeout: 30000 | ||
} | ||
}; | ||
|
||
exports.default = config; | ||
``` | ||
|
||
### Example `.cypressrunnerrc.ts` File | ||
|
||
```ts | ||
import { CypressRunnerConfig } from '@devmy/cypress-runner'; | ||
|
||
const config: CypressRunnerConfig = { | ||
debug: true, | ||
startWebServerCommands: [ | ||
{ command: "npm run start:frontend", name: "frontend" }, | ||
{ command: "npm run start:backend", name: "backend" } | ||
], | ||
waitOn: { | ||
resources: ["http://localhost:3000", "http://localhost:4000"], | ||
delay: 1000, | ||
timeout: 30000 | ||
} | ||
}; | ||
|
||
export default config; | ||
``` | ||
|
||
## Usage | ||
|
||
After configuring your `.cypressrunnerrc` file, you can run Cypress Runner from your project’s root directory: | ||
|
||
```sh | ||
cypress-runner [cypress options] | ||
``` | ||
|
||
All additional parameters passed to the CLI will be forwarded directly to Cypress. | ||
|
||
### Example | ||
|
||
```sh | ||
cypress-runner open | ||
``` | ||
|
||
In this example, `cypress-runner` will: | ||
1. Start the frontend and backend servers as specified in the `.cypressrunnerrc` file. | ||
2. Wait until the servers are up and running based on the `waitOn` configuration. | ||
3. Launch the Cypress test runner with the `open` option. | ||
|
||
## Options | ||
|
||
### debug | ||
|
||
- **Type:** `boolean` | ||
- **Description:** Enables debug logging for the Cypress Runner. | ||
- **Default:** `false` | ||
|
||
### startWebServerCommands | ||
|
||
- **Type:** `Array<ConcurrentlyCommandInput>` | `ConcurrentlyCommandInput` | ||
- **Description:** Commands to start the frontend and backend servers. This uses the `concurrently` package to run multiple commands concurrently. | ||
|
||
### waitOn | ||
|
||
- **Type:** `WaitOnOptions` | ||
- **Description:** Configuration options for the `wait-on` package to wait for resources (such as HTTP endpoints) to become available before starting Cypress. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details. |
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,11 @@ | ||
#! /usr/bin/env node | ||
|
||
"use strict"; | ||
const { cypressRunner } = require("../dist/index.js"); | ||
|
||
cypressRunner() | ||
.then(() => process.exit(0)) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |
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 * from './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,19 @@ | ||
import * as figlet from 'figlet'; | ||
import { isNil } from 'lodash'; | ||
|
||
const figletAsync = (txt: string, options: figlet.Options | undefined) => | ||
new Promise((resolve, reject) => | ||
figlet(txt, options, (error, data) => { | ||
if (isNil(error)) { | ||
resolve(data); | ||
} else { | ||
reject(error); | ||
} | ||
}), | ||
); | ||
|
||
export const printBanner = async () => { | ||
const banner = await figletAsync('Cypress Runner', { font: 'Standard' }); | ||
|
||
console.log(banner + '\n\n'); | ||
}; |
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 @@ | ||
import { ConcurrentlyCommandInput } from 'concurrently'; | ||
import { WaitOnOptions } from 'wait-on'; | ||
|
||
export interface CypressRunnerConfig { | ||
debug?: boolean; | ||
startWebServerCommands: Array<ConcurrentlyCommandInput> | ConcurrentlyCommandInput; | ||
waitOn?: WaitOnOptions; | ||
} |
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,7 @@ | ||
export * from './banner'; | ||
export * from './cypress-runner-config'; | ||
export * from './kill-concurrently-result'; | ||
export * from './load-configuration'; | ||
export * from './runner'; | ||
export * from './start-web-server-commands'; | ||
export * from './wait-web-services'; |
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 @@ | ||
import { ConcurrentlyResult } from 'concurrently'; | ||
|
||
export const killConcurrentlyResult = async ( | ||
concurrentlyResult: ConcurrentlyResult, | ||
): Promise<void> => { | ||
concurrentlyResult.commands | ||
.filter((command) => !(command.exited || command.killed)) | ||
.forEach((command) => { | ||
console.info(`Shutting down ${command.command}`); | ||
command.kill(); | ||
console.info(`✅ ${command.name ?? command.command} has been successfully shut down`); | ||
}); | ||
|
||
await concurrentlyResult.result; | ||
}; |
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,33 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { register } from 'ts-node'; | ||
import { CypressRunnerConfig } from './cypress-runner-config'; | ||
|
||
export const loadConfiguration = (): CypressRunnerConfig => { | ||
const configFileName = '.cypressrunnerrc'; | ||
const extensions = ['', '.json', '.js', '.ts']; | ||
|
||
for (const ext of extensions) { | ||
const filePath = path.resolve(process.cwd(), configFileName + ext); | ||
|
||
if (fs.existsSync(filePath)) { | ||
if (ext === '.json' || ext === '') { | ||
return JSON.parse(fs.readFileSync(filePath, 'utf-8')); | ||
} else if (ext === '.js') { | ||
return require(filePath); | ||
} else if (ext === '.ts') { | ||
register({ | ||
transpileOnly: true, | ||
compilerOptions: { | ||
module: 'commonjs' | ||
} | ||
}); | ||
const tsConfig = require(filePath).default; | ||
} | ||
} | ||
} | ||
|
||
throw new Error('No configuration file found. Please create a .cypressrunnerrc file with the appropriate format (json, js, ts).'); | ||
}; | ||
|
||
|
Oops, something went wrong.