Skip to content

Commit

Permalink
Code renames (testimio#10)
Browse files Browse the repository at this point in the history
* More SP to RC renames

* more renames
  • Loading branch information
Bnaya Peretz authored Sep 3, 2020
1 parent cffc2bd commit 089eb9c
Show file tree
Hide file tree
Showing 33 changed files with 194 additions and 427 deletions.
4 changes: 2 additions & 2 deletions infra-scripts/codelessTestRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ async function codelessTestRun() {
--tunnel-host-header "https://localhost:3000" \
--tunnel-use-http-address \
--options-file codelessProjectConfig.json \
--suite "Screenplay local client ui" \
--report-file reporters-output/screenplay-ui.xml
--suite "root-cause local client ui" \
--report-file reporters-output/root-cause-ui.xml
`,
},
], {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"metadata": {
"testName": "/Users/bnaya/dev/clients/testim.io/dev-first/screenplay/packages/tester/launchFunctionTesterLogsPage.ts",
"testFullName": "1594203491368-/Users/bnaya/dev/clients/testim.io/dev-first/screenplay/packages/tester/launchFunctionTesterLogsPage.ts",
"testName": "/home/testim.io/dev-first/root-cause/packages/tester/launchFunctionTesterLogsPage.ts",
"testFullName": "1594203491368-/home/testim.io/dev-first/root-cause/packages/tester/launchFunctionTesterLogsPage.ts",
"systemInfo": {
"automationFramework": "playwright",
"browser": "chromium",
Expand Down Expand Up @@ -458,4 +458,4 @@
"name": "evaluate"
}
]
}
}
3 changes: 1 addition & 2 deletions packages/client/src/stores/MainStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function useMainStore() {
return useContext(MainStoreContext);
}

type ScreenplayStepResult = StepResult;
interface ILoadTestResult {
(): Promise<any>;
};
Expand All @@ -31,7 +30,7 @@ export class MainStore {
) {
}

@computed get steps(): ScreenplayStepResult[] {
@computed get steps(): StepResult[] {
if (this.resultsFile) {
return this.resultsFile.steps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"modelVersion": "11.3",
"browserPlatform": "MacIntel"
},
"fileName": "/Users/bnaya/dev/clients/testim.io/dev-first/screenplay-tree-2/packages/screenplay/src/assortedHooks.ts",
"fileName": "/home/testim.io/dev-first/root-cause-tree-2/packages/root-cause/src/assortedHooks.ts",
"branchInfo": {
"branchName": "TES-6362-download-har-per-step",
"commitHash": "04ea745b5dfccc297515b2958a040c404fa8524d"
Expand Down Expand Up @@ -227,4 +227,4 @@
"name": "click \"[data-job=POST_404]\""
}
]
}
}
2 changes: 1 addition & 1 deletion packages/jest-tester-and-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"test": "jest",
"local-screenplay-cli": "node ../screenplay/dist/src/cli.js"
"local-rc-cli": "node ../root-cause-core/dist/lib/cli.js"
},
"author": "",
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/root-cause-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type {
EndTestFunction, AttachParams, AttachReturn, StartTestParams, AssertionReport,
} from './lib/attachInterfaces';
export type { RootCausePage } from './lib/interfaces';
export { updateHistoryFromScreenplayResultsOnly } from './lib/updateHistoryFromScreenplayResultsOnly';
export { updateHistoryFromRootCauseResultsOnly } from './lib/updateHistoryFromRootCauseResultsOnly';

// todo: figure out packages and code sharing
// These ones should also be splited to other packages
Expand Down
2 changes: 1 addition & 1 deletion packages/root-cause-core/lib/PuppeteerPageHooker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class PuppeteerPageHooker implements IAutomationFrameworkInstrumentor {
return reflectedProperty;
}

return async function screenplayWrappedFunction(...args: any[]) {
return async function rootCauseWrappedFunction(...args: any[]) {
testContext.stepStarted();
for (const beforeHook of beforeHooks) {
try {
Expand Down
24 changes: 12 additions & 12 deletions packages/root-cause-core/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { program } from 'commander';
import open from 'open';
import { openServer } from './server';
import prompts from 'prompts';
import { constructScreenplayResultDir, constructTestResultDir } from './utils';
import { constructResultDir, constructTestResultDir } from './utils';
import { readRunsHistory, readRunConclusion } from './runConclusion/runConclusionUtils';
import { readHistoryFallback } from './updateHistoryFromScreenplayResultsOnly';
import { readHistoryFallback } from './updateHistoryFromRootCauseResultsOnly';
import { persist } from './persist';
import type { RunConclusionFile } from '@testim/root-cause-types';

Expand All @@ -23,8 +23,8 @@ program.version(getVersion());

async function show(testId?: string, { failed: showOnlyFailed = false }: { failed?: boolean } = {}) {

const screenplayPath = constructScreenplayResultDir(process.cwd());
const history = await readRunsHistory(screenplayPath);
const resultsDirPath = constructResultDir(process.cwd());
const history = await readRunsHistory(resultsDirPath);

let conclusion: RunConclusionFile|null = null;
let runId = '';
Expand All @@ -34,7 +34,7 @@ async function show(testId?: string, { failed: showOnlyFailed = false }: { faile
runId = conclusion.runId;
} catch (err) {
if (history.length === 0) {
console.log('No Screenplay runs found');
console.log('No Root Cause runs found');
console.log('Make sure you have the .root-cause directory in your working directory');
return;
}
Expand All @@ -44,7 +44,7 @@ async function show(testId?: string, { failed: showOnlyFailed = false }: { faile
if (!conclusion) {
const mostRecentHistory = history[0];
runId = mostRecentHistory.runId;
conclusion = await readRunConclusion(screenplayPath, runId);
conclusion = await readRunConclusion(resultsDirPath, runId);
}

if (testId) {
Expand Down Expand Up @@ -83,10 +83,10 @@ async function show(testId?: string, { failed: showOnlyFailed = false }: { faile
}

async function list({ simple = false, failed: showOnlyFailed = false }: { simple?: boolean; failed?: boolean } = {}) {
const screenplayPath = constructScreenplayResultDir(process.cwd());
const history = await readRunsHistory(screenplayPath);
const resultsDirPath = constructResultDir(process.cwd());
const history = await readRunsHistory(resultsDirPath);
if (history.length === 0) {
console.log('No Screenplay runs found');
console.log('No Root Cause runs found');
return;
}

Expand All @@ -98,7 +98,7 @@ async function list({ simple = false, failed: showOnlyFailed = false }: { simple
runId = conclusion.runId;
} catch (err) {
if (history.length === 0) {
console.log('No Screenplay runs found');
console.log('No Root Cause runs found');
console.log('Make sure you have the .root-cause directory in your working directory');
return;
}
Expand All @@ -108,7 +108,7 @@ async function list({ simple = false, failed: showOnlyFailed = false }: { simple
if (!conclusion) {
const mostRecentHistory = history[0];
runId = mostRecentHistory.runId;
conclusion = await readRunConclusion(screenplayPath, runId);
conclusion = await readRunConclusion(resultsDirPath, runId);
}

if (simple) {
Expand Down Expand Up @@ -169,7 +169,7 @@ program
.alias('ls')
.option('-s, --simple', 'print simple output, as unformatted as possible')
.option('-f, --failed', 'show only failed tests')
.description('list all screenplay runs')
.description('list all Root Cause tests in the last run')
.action(list);

program
Expand Down
4 changes: 2 additions & 2 deletions packages/root-cause-core/lib/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type playwright from 'playwright';
import { attach } from './attach';
import { StartTestParams } from './attachInterfaces';
import { FALLBACK_RUN_ID } from './consts';
import { updateHistoryFromScreenplayResultsOnly } from './updateHistoryFromScreenplayResultsOnly';
import { updateHistoryFromRootCauseResultsOnly } from './updateHistoryFromRootCauseResultsOnly';
import open from 'open';
import chalk from 'chalk';
import { openServer, closeServer } from './server';
Expand Down Expand Up @@ -128,7 +128,7 @@ export async function launchImpl<T extends AutomationLibrary>(

throw error;
} finally {
await updateHistoryFromScreenplayResultsOnly(
await updateHistoryFromRootCauseResultsOnly(
startTestParams.runId,
startTestParams.projectRoot,
dateConstructor
Expand Down
8 changes: 4 additions & 4 deletions packages/root-cause-core/lib/persist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestimApi } from './testim-services-api';
import { getTestimCredentials } from './testim-credentials-manager';
import { resolve as pathResolve } from 'path';
import { constructScreenplayResultDir } from './utils';
import { constructResultDir } from './utils';
import fs from 'fs-extra';
import ora from 'ora';
import untildify from 'untildify';
Expand All @@ -25,7 +25,7 @@ export async function persist(runId: string, {
}
const api = new TestimApi(process.env.SERVICES_URL);
await api.authenticate(credentials.projectId, credentials.ciToken);
const dir = constructScreenplayResultDir(projectRoot || process.cwd());
const dir = constructResultDir(projectRoot || process.cwd());
const path = pathResolve(dir, 'runs', runId);

if (!await fs.pathExists(path)) {
Expand All @@ -38,7 +38,7 @@ export async function persist(runId: string, {
resultLabel = [];
}
resultLabel.push('RootCause');
const { testimFormat } = await api.screenplayExecutions.createExecution(path, {
const { testimFormat } = await api.executionsApi.createExecution(path, {
projectId: credentials.projectId,
resultLabels: resultLabel,
// TODO(Benji) discuss with Elad, companyId is only used for
Expand Down Expand Up @@ -86,7 +86,7 @@ export function generateJunitReport({
const tests = actualTests.filter(x => x.parentResultId === file.resultId);
const failed = tests.filter(x => !x.success);
return `\t<testsuite name=${attr(file.name)} tests="${tests.length}" failure="${failed.length}" failures="${failed.length}" timestamp="${dateValue}">
${tests.map(test => `<testcase name=${attr(test.name)} classname="screenplay.test"><system-out>${baseUrl}/test/${test.testId}</system-out></testcase>`).join('\n\t\t\t\t')}
${tests.map(test => `<testcase name=${attr(test.name)} classname="rootcause.test"><system-out>${baseUrl}/test/${test.testId}</system-out></testcase>`).join('\n\t\t\t\t')}
</testsuite>`;
}).join('\n\t\t\t')}
<system-out>Suite Run URL: ${baseUrl}</system-out>
Expand Down
46 changes: 23 additions & 23 deletions packages/root-cause-core/lib/runConclusion/runConclusionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ import {
} from '../consts';
import { RootCauseRunResultEntry } from './interfaces';

export async function concludeRun(runId: string, screenplayPath: string, timestamp: number, finalResults: Map<string, {
export async function concludeRun(runId: string, rootCausePath: string, timestamp: number, finalResults: Map<string, {
runner: RunnerResultEntry;
screenplay: RootCauseRunResultEntry;
rootCause: RootCauseRunResultEntry;
}>) {
const conclusion = prepareRunConclusion(runId, timestamp, finalResults);
await writeRunConclusion(screenplayPath, runId, conclusion);
const history = await readRunsHistory(screenplayPath);
await writeRunConclusion(rootCausePath, runId, conclusion);
const history = await readRunsHistory(rootCausePath);
// We may here also actually delete old files
updateRunsHistory(history, conclusion, HISTORY_RUNS_TO_RETAIN);
await writeRunsHistory(screenplayPath, history);
await writeRunsHistory(rootCausePath, history);
}

export async function readRunsHistory(screenplayDirPath: string): Promise<RunHistoryRecord[]> {
export async function readRunsHistory(rootCauseDirPath: string): Promise<RunHistoryRecord[]> {
try {
// final may not be exits yet
// we may want to handle other errors differently
return JSON.parse(await fs.readFile(path.resolve(screenplayDirPath, HISTORY_FILE_NAME), 'utf8'));
return JSON.parse(await fs.readFile(path.resolve(rootCauseDirPath, HISTORY_FILE_NAME), 'utf8'));
} catch (e) {
return [];
}
Expand All @@ -50,21 +50,21 @@ export function updateRunsHistory(history: RunHistoryRecord[], conclusion: RunCo
history.splice(historyToKeep);
}

export async function writeRunsHistory(screenplayDirPath: string, history: RunHistoryRecord[]): Promise<void> {
return fs.writeFile(path.resolve(screenplayDirPath, HISTORY_FILE_NAME), JSON.stringify(history, null, 2));
export async function writeRunsHistory(rootCauseDirPath: string, history: RunHistoryRecord[]): Promise<void> {
return fs.writeFile(path.resolve(rootCauseDirPath, HISTORY_FILE_NAME), JSON.stringify(history, null, 2));
}

export async function writeRunConclusion(screenplayDirPath: string, runId: string, conclusion: RunConclusionFile): Promise<void> {
return fs.writeFile(path.resolve(screenplayDirPath, RUNS_DIR_NAME, runId, RUN_CONCLUSION_FILE_NAME), JSON.stringify(conclusion, null, 2));
export async function writeRunConclusion(rootCauseDirPath: string, runId: string, conclusion: RunConclusionFile): Promise<void> {
return fs.writeFile(path.resolve(rootCauseDirPath, RUNS_DIR_NAME, runId, RUN_CONCLUSION_FILE_NAME), JSON.stringify(conclusion, null, 2));
}

export async function readRunConclusion(screenplayDirPath: string, runId: string): Promise<RunConclusionFile> {
return JSON.parse(await fs.readFile(path.resolve(screenplayDirPath, RUNS_DIR_NAME, runId, RUN_CONCLUSION_FILE_NAME), 'utf8'));
export async function readRunConclusion(rootCauseDirPath: string, runId: string): Promise<RunConclusionFile> {
return JSON.parse(await fs.readFile(path.resolve(rootCauseDirPath, RUNS_DIR_NAME, runId, RUN_CONCLUSION_FILE_NAME), 'utf8'));
}

export function prepareRunConclusion(runId: string, timestamp: number, data: Map<string, {
runner: RunnerResultEntry;
screenplay: RootCauseRunResultEntry;
rootCause: RootCauseRunResultEntry;
}>): RunConclusionFile {
const conclusion: RunConclusionFile = {
runId,
Expand All @@ -75,29 +75,29 @@ export function prepareRunConclusion(runId: string, timestamp: number, data: Map
name: entry.runner.testResult.title,
fullName: entry.runner.testResult.fullName,
success: entry.runner.testResult.status === 'passed',
timestamp: entry.screenplay.testData.metadata.timestamp,
endedTimestamp: entry.screenplay.testData.metadata.endedTimestamp,
reason: entry.screenplay.testData.metadata.testEndStatus?.success === false ? (entry.screenplay.testData.metadata.testEndStatus?.error as any)?.message : undefined,
timestamp: entry.rootCause.testData.metadata.timestamp,
endedTimestamp: entry.rootCause.testData.metadata.endedTimestamp,
reason: entry.rootCause.testData.metadata.testEndStatus?.success === false ? (entry.rootCause.testData.metadata.testEndStatus?.error as any)?.message : undefined,
})),
};

return conclusion;
}

export function intersectRunnerAndScreenplay(screenplaySide: Map<string, RootCauseRunResultEntry>, runnerSide: Map<string, RunnerResultEntry>) {
export function intersectRunnerAndRootCause(rootCauseSide: Map<string, RootCauseRunResultEntry>, runnerSide: Map<string, RunnerResultEntry>) {
const finalMap = new Map<string, {
runner: RunnerResultEntry;
screenplay: RootCauseRunResultEntry;
rootCause: RootCauseRunResultEntry;
}>();

for (const [testId, screenplayEntry] of screenplaySide) {
for (const [testId, rootCauseEntry] of rootCauseSide) {
const runnerEntry = runnerSide.get(testId);

// for simplicity we ignore tests with other end status
if (screenplayEntry && runnerEntry && (runnerEntry.testResult.status === 'passed' || runnerEntry.testResult.status === 'failed')) {
if (rootCauseEntry && runnerEntry && (runnerEntry.testResult.status === 'passed' || runnerEntry.testResult.status === 'failed')) {
finalMap.set(testId, {
runner: runnerEntry,
screenplay: screenplayEntry,
rootCause: rootCauseEntry,
});
}
// if we have issues with computing correct id, we will find it here
Expand All @@ -118,7 +118,7 @@ export async function readRunResultsDirToMap(inputDir: string): Promise<Map<stri
return false;
}

// Skip directories without results SCREENPLAY_RESULTS_FILE_NAME inside them
// Skip directories without results TEST_RESULTS_FILE_NAME inside them
return fs.pathExists(path.resolve(inputDir, maybeDirPath, TEST_RESULTS_FILE_NAME));
},
{ concurrency: 4 }
Expand Down
7 changes: 1 addition & 6 deletions packages/root-cause-core/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ export async function openServer(port: number, testPath: string): Promise<string

app.use('/results', express.static(testPath));


// TODO(Benji) - we need to figure out how to bundle the dependencies from the monorepo
// in the screenplay publish
app.get('/test/', async (req: express.Request, res: express.Response) => {
try {
const results = JSON.parse((await fs.readFile(path.resolve(testPath, 'results.json'), 'utf-8')));
Expand All @@ -63,9 +60,7 @@ export async function openServer(port: number, testPath: string): Promise<string

const url = `https://localhost:${port}`;

loggerDebug(`screenplay available at: ${url}`);
/* eslint-disable-next-line no-console */
// console.log(`screenplay available at: ${url}`);
loggerDebug(`root cause available at: ${url}`);
resolve(url);
});

Expand Down
Loading

0 comments on commit 089eb9c

Please sign in to comment.