Skip to content

Commit

Permalink
chore: integration tests (#48)
Browse files Browse the repository at this point in the history
* added integration tests

* fixed unit tests

* fixes for act

* updated package, workflows

* fix ci tests
  • Loading branch information
shubhbapna authored Jun 20, 2023
1 parent a75b0a1 commit 04e1be7
Show file tree
Hide file tree
Showing 16 changed files with 778 additions and 293 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@ on:
- 'jest.config.ts'

jobs:
tests:
unit:
strategy:
matrix:
node-version: [16.x]
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install packages
run: npm ci

- name: Test
run: npm run test:unit

integration:
strategy:
matrix:
node-version: [16.x]
Expand All @@ -29,8 +48,8 @@ jobs:
run: npm ci

- name: Test
run: npm test

run: npm run test:it
lint:
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
"scripts": {
"postinstall": "node scripts/postinstall.js 0.2.45",
"build": "tsc && tsc-alias",
"pretest": "npm run postinstall && mkdir -p bin && cp build/bin/* bin/",
"test": "jest unit/",
"test:report": "npm test -- --coverage --testResultsProcessor=jest-sonar-reporter",
"pretest:ci": "npm run pretest",
"pretest:it": "npm run postinstall && mkdir -p bin && cp build/bin/* bin/",
"test": "npm run test:unit && npm run test:it",
"test:unit": "jest unit/",
"test:it": "jest test/it/*",
"test:report": "npm run test:unit -- --coverage --testResultsProcessor=jest-sonar-reporter",
"pretest:ci": "npm run pretest:it",
"test:ci": "jest ./test/ci/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand Down
9 changes: 5 additions & 4 deletions src/act/act.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,16 @@ export class Act {
if (opts?.mockSteps) {
// there could multiple workflow files with same event triggers or job names. Act executes them all
let workflowFiles: string[] = [];
const cwd = opts.cwd ?? this.cwd;

// if workflow file was defined then no need to consider all possible options
if (opts.workflowFile) {
workflowFiles = [path.basename(opts.workflowFile)];
} else if (this.workflowFile !== this.cwd) {
} else if (this.workflowFile !== cwd) {
workflowFiles = [path.basename(this.workflowFile)];
} else {
workflowFiles = (
await this.list(undefined, opts.cwd, opts.workflowFile)
await this.list(undefined, opts.cwd)
).filter(filter).map(l => l.workflowFile);
}

Expand All @@ -252,7 +253,7 @@ export class Act {
const fsStream = await this.logRawOutput(logFile);
return new Promise((resolve, reject) => {
// do not use spawnSync. will cause a deadlock when used with proxy settings
const childProcess = spawn(ACT_BINARY, ["-W", cwd, ...args], { cwd });
const childProcess = spawn(ACT_BINARY, args, { cwd });
let data = "";

childProcess.stdout.on("data", chunk => {
Expand Down Expand Up @@ -287,7 +288,7 @@ export class Act {
const workflowFile = opts?.workflowFile ?? this.workflowFile;
let proxy: ForwardProxy | undefined = undefined;

if (opts?.mockApi) {
if (opts?.mockApi && opts.mockApi.length > 0) {
proxy = new ForwardProxy(opts.mockApi);

const address = await proxy.start();
Expand Down
4 changes: 2 additions & 2 deletions test/ci/pull_request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ afterEach(async () => {
test("pull request workflow", async () => {

const act = new Act(github.repo.getPath("pull_request"));
const result = await act.setMatrix("os", ["ubuntu-latest"]).runJob("tests", {
const result = await act.setMatrix("node-version", ["16.x"]).runJob("unit", {
mockSteps: {
tests: [
unit: [
{
name: "Test",
mockWith: "echo ran tests"
Expand Down
Loading

0 comments on commit 04e1be7

Please sign in to comment.