Skip to content

Commit

Permalink
Add user flow replay (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherPHolder committed Sep 24, 2023
2 parents 6dd916e + 7af170a commit 36c6ef2
Show file tree
Hide file tree
Showing 124 changed files with 8,144 additions and 1,460 deletions.
64 changes: 32 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,35 @@ jobs:
if: ${{ env.is-main-branch == 'true' }}
run: npx nx affected --target=deploy --environment=prod

# deploy-server:
# name: Deploy Server
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v3
#
# - uses: actions/setup-node@v3
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: npm
#
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: eu-central-1
#
# - name: Install dependencies
# run: npm install
#
# - name: Build Dev
# run: npm run build
#
# - name: Deploy Dev Server
# if: ${{ env.is-pull-request == 'true' }}
# run: npm run deploy:runner
#
# - name: Deploy Prod Server
# if: ${{ env.is-main-branch == 'true' }}
# run: npm run deploy:runner
deploy-server:
name: Deploy Server
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-central-1

- name: Install dependencies
run: npm install

- name: Build Dev
run: npm run build

- name: Deploy Dev Server
if: ${{ env.is-pull-request == 'true' }}
run: npm run deploy:runner

- name: Deploy Prod Server
if: ${{ env.is-main-branch == 'true' }}
run: npm run deploy:runner
29 changes: 29 additions & 0 deletions .verdaccio/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# path to a directory with all packages
storage: ../tmp/local-registry/storage

auth:
htpasswd:
file: ./htpasswd

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
maxage: 60m

packages:
'**':
# give all users (including non-authenticated users) full access
# because it is a local registry
access: $all
publish: $all
unpublish: $all

# if package is not available locally, proxy requests to npm registry
proxy: npmjs

# log settings
logs:
type: stdout
format: pretty
level: http
1 change: 1 addition & 0 deletions .verdaccio/htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test:$6FrCaT/v0dwE:autocreated 2020-03-25T19:10:50.254Z
10 changes: 10 additions & 0 deletions apps/audit-runner-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
22 changes: 22 additions & 0 deletions apps/audit-runner-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "audit-runner-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"implicitDependencies": ["audit-runner"],
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nx/vite:test",
"outputs": ["{workspaceRoot}/coverage/{e2eProjectRoot}"],
"options": {
"passWithNoTests": true
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/audit-runner-e2e/**/*.{js,ts}"]
}
}
}
}
18 changes: 18 additions & 0 deletions apps/audit-runner-e2e/src/audit-runner/commands/user-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, it, expect } from 'vitest';
import { execSync } from 'child_process';

import { getCliPath } from '../utils';

describe('user-flow command', () => {
const cliPath = getCliPath();
const execPath = `node ${cliPath}`;

function commandOutput(args: string): string {
return execSync(`${execPath} ${args}`).toString()
}

it('should print a help message', () => {
const u = commandOutput(`uf --queue local --dry-run`);
expect(u).toBe('');
});
});
54 changes: 54 additions & 0 deletions apps/audit-runner-e2e/src/audit-runner/help/help.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, it, expect } from 'vitest';
import { execSync } from 'child_process';

import { getCliPath } from '../utils';

const helpOutput = {
headers: [
'audit-runner',
'Commands:',
'Options:',
],
commands: [
'audit-runner user-flow Load, Run and Store user-flow audits',
],
options: [
'--version Show version number',
'-v, --verbose Run with verbose logging',
'-h, --help Show help'
]
}

describe('help argument', () => {
const cliPath = getCliPath();
const execPath = `node ${cliPath}`;

function commandOutput(args: string): string {
return execSync(`${execPath} ${args}`).toString()
}

function expectHelpLog(commandOutput: string): void {
helpOutput.headers.forEach(header => expect(commandOutput).toContain(header));
helpOutput.commands.forEach(commands => expect(commandOutput).toContain(commands));
helpOutput.options.forEach(options => expect(commandOutput).toContain(options));
}

it('should print a help message', () => {
expectHelpLog(commandOutput('--help'));
expectHelpLog(commandOutput('--help true'));
expectHelpLog(commandOutput('-h'));
expectHelpLog(commandOutput('-h true'));
});
it('should print a help command with and error message', () => {
let errorMessage = '';
try {
commandOutput('');
} catch (e) {
if (e instanceof Error) {
errorMessage = e.message;
}
}
expectHelpLog(errorMessage);
expect(errorMessage).toContain('Not enough non-option arguments: got 0, need at least 1');
})
});
8 changes: 8 additions & 0 deletions apps/audit-runner-e2e/src/audit-runner/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { join } from 'node:path';

// this is a quick fix, ether implement a proper solution of fix the issue with configs
export const getCliPath = (): string => {
const cwd = process.cwd();
const rootPath = cwd.includes('audit-runner-e2e') ? '../../' : '';
return join(process.cwd(), rootPath, 'dist/apps/audit-runner');
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
],
"compilerOptions": {
"esModuleInterop": true,
"types": ["vitest"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"]
},
"include": [
"jest.config.ts",
"vite.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
Expand Down
3 changes: 3 additions & 0 deletions apps/audit-runner-e2e/user-flow/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"example": "Example"
}
3 changes: 3 additions & 0 deletions apps/audit-runner-e2e/user-flow/example1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"example": "Example1"
}
32 changes: 32 additions & 0 deletions apps/audit-runner-e2e/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';

import viteTsConfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
cacheDir: '../../node_modules/.vite/audit-runner-e2e',

plugins: [
viteTsConfigPaths({
root: '../../',
}),
],

// Uncomment this if you are using workers.
// worker: {
// plugins: [
// viteTsConfigPaths({
// root: '../../',
// }),
// ],
// },

test: {
globals: true,
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'node',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
});
File renamed without changes.
76 changes: 76 additions & 0 deletions apps/audit-runner/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "audit-runner",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/audit-runner/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"platform": "node",
"outputPath": "dist/apps/audit-runner",
"format": ["esm"],
"bundle": true,
"main": "apps/audit-runner/src/main.ts",
"tsConfig": "apps/audit-runner/tsconfig.app.json",
"assets": ["apps/audit-runner/src/assets"],
"generatePackageJson": true,
"esbuildOptions": {
"sourcemap": true,
"outExtension": {
".js": ".js"
}
}
},
"configurations": {
"development": {},
"production": {
"esbuildOptions": {
"sourcemap": false,
"outExtension": {
".js": ".js"
}
}
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "audit-runner:build"
},
"configurations": {
"development": {
"buildTarget": "audit-runner:build:development"
},
"production": {
"buildTarget": "audit-runner:build:production"
}
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/audit-runner/**/*.ts"]
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
},
"tags": []
}
10 changes: 10 additions & 0 deletions apps/audit-runner/src/args/dry-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Options } from 'yargs';

export const dryRun: Options = {
default: false,
type: 'boolean'
}

export interface DryRunOption {
dryRun?: boolean;
}
7 changes: 7 additions & 0 deletions apps/audit-runner/src/args/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DryRunOption, dryRun } from './dry-run';
import { HelpOption, help } from './help';
import { ShutdownOption, shutdown } from './shutdown';
import { VerboseOption, verbose } from './verbose';

export type GlobalOptions = DryRunOption & HelpOption & ShutdownOption & VerboseOption;
export { dryRun, help, shutdown, verbose };
12 changes: 12 additions & 0 deletions apps/audit-runner/src/args/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Options } from 'yargs';

export const help: Options = {
alias: 'h',
default: false,
type: 'boolean'
}

export interface HelpOption {
help: boolean;
h: boolean;
}
Loading

0 comments on commit 36c6ef2

Please sign in to comment.