Skip to content

Commit

Permalink
fix: demo patch-package
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Dec 26, 2023
1 parent b2aff81 commit 172df44
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 4 deletions.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
"scripts": {
"acceptance_test": "mocha test/acceptance_test.js --timeout 50000",
"bdd_acceptance_test": "mocha test/bdd_acceptance_test.js --timeout 50000",
"test": "npm run acceptance_test && npm run bdd_acceptance_test"
"test": "npm run acceptance_test && npm run bdd_acceptance_test",
"postinstall": "patch-package"
},
"devDependencies": {
"@faker-js/faker": "^8.3.1",
"@types/node": "^20.10.5",
"eslint": "6.6.0",
"eslint-config-airbnb-base": "14.0.0",
"eslint-plugin-import": "2.18.2"
Expand All @@ -38,7 +41,11 @@
"assert": "2.1.0",
"axios": "1.6.2",
"chai": "4.3.10",
"faker": "^6.6.6",
"joi": "^17.11.0",
"mocha": "10.2.0",
"playwright": "1.39.0"
"patch-package": "^8.0.0",
"playwright": "1.39.0",
"ts-node": "^10.9.2"
}
}
19 changes: 19 additions & 0 deletions patches/codeceptjs+3.5.10.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/node_modules/codeceptjs/lib/command/workers/runTests.js b/node_modules/codeceptjs/lib/command/workers/runTests.js
index 430a7b4..b47593d 100644
--- a/node_modules/codeceptjs/lib/command/workers/runTests.js
+++ b/node_modules/codeceptjs/lib/command/workers/runTests.js
@@ -141,6 +141,14 @@ function initializeListeners() {
const _steps = [];

for (step of steps) {
+ const _args = [];
+
+ if (step.args) {
+ for (const arg of step.args) {
+ arg && arg.$_root ? _args.push(JSON.stringify(arg).slice(0, 300)) : _args.push(arg);
+ }
+ }
+
_steps.push({
actor: step.actor,
name: step.name,
12 changes: 11 additions & 1 deletion test/acceptance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { exec } = require('child_process');
const { expect } = require('chai');

const runner = './node_modules/.bin/codeceptjs run-workers 2 rp_plugin_test.js';
const configFilePath = './test/codecept.conf.js';
const configFilePath = './test/codecept.conf.ts';

describe('RP Plugin - Codeceptjs Integration', () => {
describe('Passed test', () => {
Expand All @@ -22,4 +22,14 @@ describe('RP Plugin - Codeceptjs Integration', () => {
});
});
});

describe('API test with Joi Object', () => {
it('should push data to rp', (done) => {
exec(`${runner} --grep @api -c ${configFilePath} --verbose`, (error, stdout, stderr) => {
console.log(stdout)
expect(stdout).to.include('Success start launch with tempId');
done();
});
});
});
});
2 changes: 1 addition & 1 deletion test/bdd_acceptance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { exec } = require('child_process');
const { expect } = require('chai');

const runner = './node_modules/.bin/codeceptjs run-workers 2 features/basic.feature';
const configFilePath = './test/codecept.conf.js';
const configFilePath = './test/codecept.conf.ts';

describe('RP Plugin - Codeceptjs Integration - BDD Feature', () => {
describe('Passed test', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/codecept.conf.js → test/codecept.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ exports.config = {
url: 'https://www.google.de/',
show: false,
},
JSONResponse: {},
REST: {
endpoint: 'https://reqres.in',
timeout: 30_000
},
},
include: {},
mocha: {},
Expand Down
35 changes: 35 additions & 0 deletions test/rp_plugin_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
const {I} = inject();
const Joi = require('joi');
const faker = require('@faker-js/faker');

const resSchemaForImporting = Joi.object({
status: Joi.number().valid(200).required(),
msg: Joi.string().valid('Started sync successfully.').required(),
messages: Joi.array().length(0).required(),
localized_messages: Joi.array().length(0).required(),
errors: Joi.array().length(0).required(),
request: Joi.object({
host: Joi.string().required(),
id: Joi.string().guid({ version: 'uuidv4' }).required()
}).required()
}).required();

let createdUser;

Feature('RP Plugin tests');

async function createNewUser(userData) {
let payload = userData || {
name: faker.name.firstName(),
job: 'leader'
};

return I.sendPostRequest('/api/users', payload);
}

Before(async () => {
createdUser = await createNewUser();
});

Scenario('Send passed results to RP @pass', () => {
I.amOnPage('/');
I.dontSee('abc');
Expand All @@ -11,3 +40,9 @@ Scenario('Send failed results to RP @fail', () => {
I.amOnPage('/');
I.see('abcdef');
});

Scenario('API tests with joi @api', async () => {
let id = createdUser['data']['id'];
await I.sendDeleteRequest(`/api/users/${id}`);
I.seeResponseMatchesJsonSchema(resSchemaForImporting);
});
11 changes: 11 additions & 0 deletions test/steps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types='codeceptjs' />


declare namespace CodeceptJS {
interface SupportObject { I: I, current: any }
interface Methods extends Playwright, JSONResponse, REST {}
interface I extends WithTranslation<Methods> {}
namespace Translation {
interface Actions {}
}
}

0 comments on commit 172df44

Please sign in to comment.