Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelPanic92 committed Jun 3, 2024
1 parent 855ad0b commit 952f741
Show file tree
Hide file tree
Showing 20 changed files with 4,673 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
package.json
./node_modules/
.vscode
.idea
50 changes: 50 additions & 0 deletions .eslintrc.json
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"
]
}
]
}
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "auto",
"printWidth": 100
}
22 changes: 22 additions & 0 deletions .releaserc.js
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;
136 changes: 136 additions & 0 deletions README.md
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 { CypressRunnerConfigfrom '@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.
11 changes: 11 additions & 0 deletions bin/cypress-runner.js
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);
});
1 change: 1 addition & 0 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './runner';
19 changes: 19 additions & 0 deletions lib/src/runner/banner.ts
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');
};
8 changes: 8 additions & 0 deletions lib/src/runner/cypress-runner-config.ts
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;
}
7 changes: 7 additions & 0 deletions lib/src/runner/index.ts
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';
15 changes: 15 additions & 0 deletions lib/src/runner/kill-concurrently-result.ts
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;
};
33 changes: 33 additions & 0 deletions lib/src/runner/load-configuration.ts
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).');
};


Loading

0 comments on commit 952f741

Please sign in to comment.