Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update component test and generate reports #2989

Merged
merged 17 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
58 changes: 58 additions & 0 deletions .github/workflows/component-test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Component Test Reporter

on:
pull_request:
types:
- opened
- reopened
- synchronize

jobs:
test_and_upload:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 1

- name: Setup Node
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Install Dependencies
run: npm ci

- name: Run Tests and Generate Report
run: |
npm run test:ts -- component

- name: Upload Report to S3
uses: jakejarvis/[email protected]
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SRC: ./test_reports/
DEST: /integrations-test-reports/${{ github.run_number }}/
- name: Comment on PR with S3 Object URL
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const runNumber = process.env.GITHUB_RUN_NUMBER;
const commentBody = `Test report for this run is available at: https://company.s3.amazonaws.com/integrations-test-reports/${runNumber}/test-report.html`;

// Get the pull request number
const prNumber = context.payload.pull_request.number;

// Comment on the pull request
await github.issues.createComment({ owner, repo, issue_number: prNumber, body: commentBody });


5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ dist
**/.DS_Store


.idea
.idea

# component test report
test_reports/
24 changes: 24 additions & 0 deletions test/integrations/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import tags from '../../src/v0/util/tags';
import { Server } from 'http';
import { appendFileSync } from 'fs';
import { responses } from '../testHelper';
import { generateTestReport, initaliseReport } from '../test_reporter/reporter';
import _ from 'lodash';

// To run single destination test cases
// npm run test:ts -- component --destination=adobe_analytics
Expand All @@ -37,6 +39,7 @@ command
.option('-f, --feature <string>', 'Enter Feature Name(processor, router)')
.option('-i, --index <number>', 'Enter Test index')
.option('-g, --generate <string>', 'Enter "true" If you want to generate network file')
.option('-id, --id <string>', 'Enter unique "Id" of the test case you want to run')
.parse();

const opts = command.opts();
Expand All @@ -50,7 +53,10 @@ if (opts.generate === 'true') {

let server: Server;

const REPORT_COMPATIBLE_INTEGRATION = ['klaviyo'];
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved

beforeAll(async () => {
initaliseReport();
const app = new Koa();
app.use(
bodyParser({
Expand Down Expand Up @@ -124,6 +130,16 @@ const testRoute = async (route, tcData: TestCaseData) => {
const outputResp = tcData.output.response || ({} as any);
expect(response.status).toEqual(outputResp.status);

if (REPORT_COMPATIBLE_INTEGRATION.includes(tcData.name?.toLocaleLowerCase())) {
const bodyMatched = _.isEqual(response.body, outputResp.body);
const statusMatched = response.status === outputResp.status;
if (bodyMatched && statusMatched) {
generateTestReport(tcData, response.body, 'passed');
koladilip marked this conversation as resolved.
Show resolved Hide resolved
} else {
generateTestReport(tcData, response.body, 'failed');
}
}

if (outputResp?.body) {
expect(response.body).toEqual(outputResp.body);
}
Expand Down Expand Up @@ -181,6 +197,14 @@ describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => {
if (opts.index !== undefined) {
testData = [testData[parseInt(opts.index)]];
}
if (opts.id) {
testData = testData.filter((data) => {
if (data['id'] === opts.id) {
return true;
}
return false;
});
}
describe(`${testData[0].name} ${testData[0].module}`, () => {
test.each(testData)('$feature -> $description', async (tcData) => {
tcData?.mockFns?.(mockAdapter);
Expand Down
Loading
Loading