Skip to content

Commit 84f4188

Browse files
committed
cypress cli initial commit
0 parents  commit 84f4188

File tree

14 files changed

+1788
-0
lines changed

14 files changed

+1788
-0
lines changed

.eslintrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
3+
parserOptions: {
4+
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
5+
sourceType: "module" // Allows for the use of imports
6+
},
7+
extends: [
8+
"plugin:@typescript-eslint/recommended" // Uses the recommended rules from the @typescript-eslint/eslint-plugin
9+
],
10+
rules: {
11+
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
12+
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
13+
}
14+
};

.gitignore

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
# typescript output
107+
lib/

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 80,
6+
"useTabs": true
7+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## This will soon host the Cypress CLI for running tests on TestingBot

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "testingbot-cypress-cli",
3+
"version": "1.0.0",
4+
"description": "Run Cypress tests on TestingBot.com's Browser Grid",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"lint": "eslint --ext ts src/",
8+
"make": "tsc",
9+
"start": "node lib/index.js",
10+
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write"
11+
},
12+
"keywords": [
13+
"cypress",
14+
"testingbot"
15+
],
16+
"author": "Jochen Delabie <[email protected]>",
17+
"license": "MIT",
18+
"devDependencies": {
19+
"@types/archiver": "^3.1.0",
20+
"@types/node": "^14.0.26",
21+
"@types/yargs": "^15.0.5",
22+
"@typescript-eslint/eslint-plugin": "^3.8.0",
23+
"@typescript-eslint/parser": "^3.8.0",
24+
"eslint": "^7.6.0",
25+
"prettier": "^2.0.5",
26+
"typescript": "^3.9.7"
27+
},
28+
"dependencies": {
29+
"archiver": "^5.0.0",
30+
"tracer": "^1.1.3",
31+
"yargs": "^15.4.1"
32+
}
33+
}

src/commands/init.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import fs from 'fs';
2+
import log from './../log';
3+
import path from 'path';
4+
import config from './../templates/config';
5+
6+
const fsPromises = fs.promises;
7+
8+
interface Arguments {
9+
[x: string]: unknown;
10+
p: string | boolean;
11+
}
12+
13+
export default class InitProject {
14+
private path = '.';
15+
16+
constructor(argv: Arguments) {
17+
if (argv.p) {
18+
this.path = argv.p as string;
19+
}
20+
21+
this.generate();
22+
}
23+
24+
private async generate(): Promise<void> {
25+
let dirExists = false;
26+
27+
try {
28+
const dirStat = await fsPromises.stat(this.path);
29+
dirExists = dirStat.isDirectory();
30+
} catch (e) {}
31+
32+
if (!dirExists) {
33+
log.error(`Directory ${this.path} does not exist`);
34+
return;
35+
}
36+
37+
await fsPromises.writeFile(
38+
path.join(this.path, `testingbot.json`),
39+
config(),
40+
);
41+
}
42+
}

src/commands/run.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import log from '../log';
2+
import Archiver from '../utils/archiver';
3+
import Uploader from '../utils/uploader';
4+
5+
interface Arguments {
6+
[x: string]: unknown;
7+
p: string | boolean;
8+
}
9+
10+
export default class RunProject {
11+
private path = '.';
12+
private archiver: Archiver;
13+
private uploader: Uploader;
14+
15+
constructor(argv: Arguments) {
16+
this.archiver = new Archiver({
17+
cypress_path: '.',
18+
});
19+
20+
this.uploader = new Uploader({
21+
cypress_path: '',
22+
});
23+
}
24+
25+
public async start(): Promise<void> {
26+
let zipFile: string | undefined;
27+
28+
try {
29+
zipFile = await this.archiver.start();
30+
} catch (err) {
31+
log.error(err);
32+
return;
33+
}
34+
35+
const success = await this.uploader.start();
36+
}
37+
}

src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as yargs from 'yargs';
2+
import InitProject from './commands/init';
3+
4+
process.removeAllListeners('warning');
5+
6+
yargs
7+
.usage('usage: $0 <command>')
8+
.alias('v', 'version')
9+
.describe('v', '1.0')
10+
.command('init', 'more info', function (yargs) {
11+
const initArgv = yargs
12+
.usage('usage: $0 init [options]')
13+
.options({
14+
p: {
15+
alias: 'path',
16+
default: false,
17+
description:
18+
'The path where we need to initialize the Cypress+TestingBot config file',
19+
type: 'string',
20+
},
21+
})
22+
.help('help')
23+
.wrap(null).argv;
24+
25+
return new InitProject(initArgv);
26+
})
27+
.alias('h', 'help')
28+
.help('help')
29+
.wrap(null).argv;

src/log.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import tracer from 'tracer';
2+
3+
const logger = tracer.colorConsole({
4+
level: 'info',
5+
format: '{{timestamp}} {{file}}:{{line}} {{title}}: {{message}}',
6+
dateformat: 'HH:MM:ss.L',
7+
});
8+
9+
export default logger;

src/templates/config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export default (): string => {
2+
const config = {
3+
auth: {
4+
key: '<Your TestingBot key>',
5+
secret: '<Your TestingBot secret>',
6+
},
7+
browsers: [
8+
{
9+
browserName: 'chrome',
10+
platform: 'Windows 10',
11+
versions: ['78', '77'],
12+
},
13+
{
14+
browserName: 'firefox',
15+
os: 'Mojave',
16+
versions: ['74', '75'],
17+
},
18+
],
19+
run_settings: {
20+
cypress_project_dir:
21+
'/path/to/directory-that-contains-<cypress.json>-file',
22+
project_name: 'project-name',
23+
build_name: 'build-name',
24+
parallel_count: 'How many tests you want to run in parallel',
25+
npm_dependencies: {},
26+
package_config_options: {},
27+
},
28+
};
29+
30+
return JSON.stringify(config, null, 4);
31+
};

0 commit comments

Comments
 (0)