Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 2022, "sourceType": "module" },
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
},
"ignorePatterns": ["dist/", "node_modules/", "lib/"]
}
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
pull_request:
push:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build

- name: Check dist is up to date
run: |
if [ -n "$(git status --porcelain dist/)" ]; then
echo "::error::dist/ is out of date. Run 'npm run build' and commit."
git diff dist/ | head -100
exit 1
fi
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# PrestaFlow — GitHub Action

Run [PrestaFlow](https://prestaflow.io) tests in your GitHub Actions workflows.

## Quick start

```yaml
- uses: PrestaFlow/github-action@v2
with:
token: ${{ secrets.PRESTAFLOW_TOKEN }}
projectId: '42'
```

## With Flashlight (auto-provision PrestaShop)

```yaml
- uses: PrestaFlow/github-action@v2
with:
token: ${{ secrets.PRESTAFLOW_TOKEN }}
projectId: '42'
flashlight: true
ps-version: '9.0.0'
```

## Documentation

Full docs, guides, and reference: **https://prestaflow.io/docs/library/1/digging-deeper/github-actions**

## Migration from v1

v1 usage (`token` + `projectId` only) continues to work unchanged. See the migration section in the docs.
1 change: 1 addition & 0 deletions __tests__/fixtures/composer.module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "name": "prestaflow/my-module", "type": "prestashop-module" }
1 change: 1 addition & 0 deletions __tests__/fixtures/composer.theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "name": "prestaflow/my-theme", "type": "prestashop-theme" }
16 changes: 16 additions & 0 deletions __tests__/fixtures/results.failure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"suites": [
{
"suite": "BackOfficeSuite",
"title": "Back office",
"stats": { "passes": 42, "failures": 3, "skips": 0, "skippeds": 2, "todos": 0, "assertions": 200, "time": 134000 },
"tests": [
{ "title": "Can create a simple product", "state": "fail", "expect": { "fail": ["Timeout waiting for selector `#submit_form` (30000ms)"] }, "file": "/repo/tests/BackOffice/Products/CreateProductTest.php", "line": 42, "time": 30000 },
{ "title": "Can filter by status", "state": "fail", "expect": { "fail": ["Expected element to be visible: `.order-status-filter`"] }, "file": "/repo/tests/BackOffice/Orders/FilterTest.php", "line": 28, "time": 1500 },
{ "title": "Add to cart", "state": "fail", "expect": { "fail": ["HTTP 500 on POST /cart"] }, "file": "/repo/tests/FrontOffice/Cart/AddTest.php", "line": 15, "time": 800 }
],
"warnings": [],
"screens": []
}
]
}
18 changes: 18 additions & 0 deletions __tests__/fixtures/results.multi-suite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"suites": [
{
"suite": "S1",
"title": "First",
"stats": { "passes": 5, "failures": 1, "skips": 0, "skippeds": 0, "todos": 0, "assertions": 10, "time": 1000 },
"tests": [
{ "title": "t1", "state": "fail", "expect": { "fail": ["e1"] }, "file": "/a.php", "line": 1, "time": 100 }
]
},
{
"suite": "S2",
"title": "Second",
"stats": { "passes": 3, "failures": 0, "skips": 1, "skippeds": 0, "todos": 2, "assertions": 5, "time": 500 },
"tests": []
}
]
}
12 changes: 12 additions & 0 deletions __tests__/fixtures/results.success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"suites": [
{
"suite": "S1",
"title": "Suite 1",
"stats": { "passes": 47, "failures": 0, "skips": 0, "skippeds": 0, "todos": 0, "assertions": 100, "time": 134000 },
"tests": [],
"warnings": [],
"screens": []
}
]
}
29 changes: 29 additions & 0 deletions __tests__/flashlight/compose-template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { renderCompose } from '../../src/flashlight/compose-template';

describe('renderCompose', () => {
it('renders with all placeholders substituted', () => {
const yml = renderCompose({
psVersion: '9.0.0',
port: 8000,
workspace: '/home/runner/work/x/x',
containerPath: '/var/www/html/modules/x',
});
expect(yml).toContain('prestashop/prestashop-flashlight:9.0.0');
expect(yml).toContain('"8000:80"');
expect(yml).toContain('/home/runner/work/x/x:/var/www/html/modules/x');
expect(yml).toContain('PS_DOMAIN: localhost:8000');
});

it('accepts alternative port and version', () => {
const yml = renderCompose({
psVersion: 'latest',
port: 8002,
workspace: '/w',
containerPath: '/var/www/html/themes/t',
});
expect(yml).toContain('prestashop/prestashop-flashlight:latest');
expect(yml).toContain('"8002:80"');
expect(yml).toContain('PS_DOMAIN: localhost:8002');
expect(yml).toContain('/w:/var/www/html/themes/t');
});
});
37 changes: 37 additions & 0 deletions __tests__/flashlight/docker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as net from 'net';
import { pickPort } from '../../src/flashlight/docker';

function occupy(port: number): Promise<net.Server> {
return new Promise((resolve, reject) => {
const s = net.createServer();
s.once('error', reject);
s.listen(port, '127.0.0.1', () => resolve(s));
});
}

function close(s: net.Server): Promise<void> {
return new Promise(resolve => s.close(() => resolve()));
}

describe('pickPort', () => {
it('returns first free port among candidates', async () => {
const s = await occupy(18000);
try {
const port = await pickPort([18000, 18001, 18002]);
expect(port).toBe(18001);
} finally {
await close(s);
}
});

it('throws when all candidates busy', async () => {
const s1 = await occupy(18010);
const s2 = await occupy(18011);
try {
await expect(pickPort([18010, 18011])).rejects.toThrow(/no free port/i);
} finally {
await close(s1);
await close(s2);
}
});
});
44 changes: 44 additions & 0 deletions __tests__/flashlight/mount.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { resolveMount } from '../../src/flashlight/mount';

describe('resolveMount', () => {
it('module type mounts under modules/', () => {
const r = resolveMount({
composerJson: { name: 'prestaflow/my-module', type: 'prestashop-module' },
workspaceBasename: 'my-module',
});
expect(r.containerPath).toBe('/var/www/html/modules/my-module');
expect(r.warning).toBeUndefined();
});

it('theme type mounts under themes/', () => {
const r = resolveMount({
composerJson: { name: 'prestaflow/my-theme', type: 'prestashop-theme' },
workspaceBasename: 'my-theme',
});
expect(r.containerPath).toBe('/var/www/html/themes/my-theme');
expect(r.warning).toBeUndefined();
});

it('falls back to basename under modules/ when composer.json missing', () => {
const r = resolveMount({ composerJson: null, workspaceBasename: 'weird-repo' });
expect(r.containerPath).toBe('/var/www/html/modules/weird-repo');
expect(r.warning).toBeTruthy();
});

it('falls back when type unknown', () => {
const r = resolveMount({
composerJson: { name: 'x/y', type: 'library' },
workspaceBasename: 'y',
});
expect(r.containerPath).toBe('/var/www/html/modules/y');
expect(r.warning).toBeTruthy();
});

it('uses composer name without slash', () => {
const r = resolveMount({
composerJson: { name: 'nosash', type: 'prestashop-module' },
workspaceBasename: 'other',
});
expect(r.containerPath).toBe('/var/www/html/modules/nosash');
});
});
53 changes: 53 additions & 0 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { parseInputs } from '../src/inputs';

function withInputs(map: Record<string, string>, eventName = 'push', fn: () => void) {
const originals: Record<string, string | undefined> = {};
for (const [k, v] of Object.entries(map)) {
const key = `INPUT_${k.toUpperCase().replace(/-/g, '_')}`;
originals[key] = process.env[key];
process.env[key] = v;
}
const origEvent = process.env.GITHUB_EVENT_NAME;
process.env.GITHUB_EVENT_NAME = eventName;
try { fn(); } finally {
for (const [k, v] of Object.entries(originals)) {
if (v === undefined) delete process.env[k]; else process.env[k] = v;
}
if (origEvent === undefined) delete process.env.GITHUB_EVENT_NAME;
else process.env.GITHUB_EVENT_NAME = origEvent;
}
}

describe('parseInputs', () => {
it('parses v1-minimal input (token + projectId)', () => {
withInputs({ token: 'tok', projectId: '42' }, 'push', () => {
const i = parseInputs();
expect(i.token).toBe('tok');
expect(i.projectId).toBe('42');
expect(i.execute).toBe(true);
expect(i.suites).toEqual([]);
expect(i.flashlight).toBe(false);
expect(i.psVersion).toBe('latest');
expect(i.prComment).toBe(false);
expect(i.uploadArtifacts).toBe(true);
});
});

it('parses suites CSV', () => {
withInputs({ token: 't', suites: 'BackOffice, FrontOffice' }, 'push', () => {
expect(parseInputs().suites).toEqual(['BackOffice', 'FrontOffice']);
});
});

it('defaults prComment to true in pull_request event', () => {
withInputs({ token: 't' }, 'pull_request', () => {
expect(parseInputs().prComment).toBe(true);
});
});

it('throws when token missing', () => {
withInputs({}, 'push', () => {
expect(() => parseInputs()).toThrow(/token/i);
});
});
});
32 changes: 32 additions & 0 deletions __tests__/reporter/outputs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as core from '@actions/core';
import { setOutputs } from '../../src/reporter/outputs';

jest.mock('@actions/core');

describe('setOutputs', () => {
beforeEach(() => { (core.setOutput as jest.Mock).mockClear(); });

it('sets all outputs with status=success when failed=0', () => {
setOutputs({
report: { passed: 10, failed: 0, skipped: 1, todos: 0, total: 11, durationMs: 5000, failures: [] },
reportId: 'abc',
reportUrl: 'https://app.prestaflow.io/reports/abc',
});
expect(core.setOutput).toHaveBeenCalledWith('id', 'abc');
expect(core.setOutput).toHaveBeenCalledWith('report-url', 'https://app.prestaflow.io/reports/abc');
expect(core.setOutput).toHaveBeenCalledWith('passed', 10);
expect(core.setOutput).toHaveBeenCalledWith('failed', 0);
expect(core.setOutput).toHaveBeenCalledWith('skipped', 1);
expect(core.setOutput).toHaveBeenCalledWith('total', 11);
expect(core.setOutput).toHaveBeenCalledWith('duration-ms', 5000);
expect(core.setOutput).toHaveBeenCalledWith('status', 'success');
});

it('sets status=failure when failed>0', () => {
setOutputs({
report: { passed: 9, failed: 1, skipped: 0, todos: 0, total: 10, durationMs: 5000, failures: [] },
reportId: 'x', reportUrl: 'u',
});
expect(core.setOutput).toHaveBeenCalledWith('status', 'failure');
});
});
Loading
Loading