Skip to content

Commit

Permalink
test: add ability to add setup steps to integration tests (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Jun 18, 2021
1 parent 134225a commit 50bf29c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions integration-tests/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@
"en/**/*.md"
],
"commit": "165dc45bd31449019425b28b2ed48f78b02710a2"
},
{
"path": "streetsidesoftware/cspell-dicts",
"url": "https://github.com/streetsidesoftware/cspell-dicts.git",
"postCheckoutSteps": [
"yarn"
],
"args": [
"**/*.*"
],
"commit": "3e04648f52500fc5ffa4c4c02644ad07a10173be"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Repository: streetsidesoftware/cspell-dicts
Url: "https://github.com/streetsidesoftware/cspell-dicts.git"
Args: ["**/*.*"]
Lines:
CSpell: Files checked: 1047, Issues found: 3 in 2 files
exit code: 1
./generator-cspell-dicts/README.md:20:1 - Unknown word (mkdir) -- mkdir monkey
./generator-cspell-dicts/package.json:23:6 - Unknown word (yosay) -- "yosay": "^2.0.2"
./generator-cspell-dicts/package.json:4:46 - Unknown word (subprojects) -- Generate cspell dictionary subprojects.",
21 changes: 21 additions & 0 deletions integration-tests/src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ async function execCheck(context: CheckContext, update: boolean): Promise<CheckR
return Promise.resolve({ success: false, rep, elapsedTime: 0 });
}
log(time());
if (!(await execPostCheckoutSteps(context))) {
logger.log('******** fail ********');
return Promise.resolve({ success: false, rep, elapsedTime: 0 });
}
log(time());
const cspellResult = await execCommand(logger, path, cspellCommand, rep.args);
log(resultReport(cspellResult));
const r = checkResult(rep, cspellResult, update);
Expand Down Expand Up @@ -127,6 +132,22 @@ async function execCommand(logger: Logger, path: string, command: string, args:
});
}

async function execPostCheckoutSteps(context: CheckContext) {
const { rep, logger } = context;
const path = Path.join(repositoryDir, rep.path);

const steps = rep.postCheckoutSteps || [];
for (const step of steps) {
logger.log(`Step: %j`, step);
const r = await execCommand(logger, path, step, []);
if (r.code !== 0) {
logger.error(r.stderr);
return false;
}
}
return true;
}

function resultReport(result: Result) {
const fullOutputLines = formatExecOutput(result).split('\n');
return (fullOutputLines.length > 7 ? '...\n' : '') + fullOutputLines.slice(-7).join('\n');
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ export function addRepository(path: string, url: string, commit: string, branch:
const entries = new Map<string, Repository>(config.repositories.map((r) => [r.path, r]));
const existingEntry: Partial<Repository> = entries.get(path) || {};
const args = existingEntry.args || ['**/*.*'];
const postCheckoutSteps = existingEntry.postCheckoutSteps;

const entry: Repository = {
...existingEntry,
path,
url,
postCheckoutSteps,
args,
commit,
branch,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/configDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface Repository {
branch: string | undefined;
commit: string;
args: string[];
postCheckoutSteps: string[] | undefined;
}
1 change: 1 addition & 0 deletions integration-tests/src/repositoryHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Validate repository helper', () => {
commit: '',
branch: undefined,
args: [],
postCheckoutSteps: undefined,
}));
});

Expand Down

0 comments on commit 50bf29c

Please sign in to comment.