Skip to content

Commit

Permalink
feat: add support filtering component tests by feature and index (#2748)
Browse files Browse the repository at this point in the history
* feat: add support filtering component tests by feature and index

* feat: add support filtering component tests by feature and index
  • Loading branch information
koladilip authored Oct 19, 2023
1 parent 5f094bc commit 146f1c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 9 additions & 2 deletions test/integrations/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { responses } from '../testHelper';

// To run single destination test cases
// npm run test:ts -- component --destination=adobe_analytics
// npm run test:ts -- component --destination=adobe_analytics --feature=router
// npm run test:ts -- component --destination=adobe_analytics --feature=router --index=0

// Use below command to generate mocks
// npm run test:ts -- component --destination=zendesk --generate=true
Expand All @@ -32,6 +34,8 @@ const command = new Command();
command
.allowUnknownOption()
.option('-d, --destination <string>', 'Enter Destination Name')
.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')
.parse();

Expand Down Expand Up @@ -91,7 +95,7 @@ if (!opts.generate || opts.generate === 'false') {

// END
const rootDir = __dirname;
const allTestDataFilePaths = getTestDataFilePaths(rootDir, opts.destination);
const allTestDataFilePaths = getTestDataFilePaths(rootDir, opts);
const DEFAULT_VERSION = 'v0';

const testRoute = async (route, tcData: TestCaseData) => {
Expand Down Expand Up @@ -174,7 +178,10 @@ describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => {
jest.clearAllMocks();
});
// add special mocks for specific destinations
const testData: TestCaseData[] = getTestData(testDataPath);
let testData: TestCaseData[] = getTestData(testDataPath);
if (opts.index !== undefined) {
testData = [testData[parseInt(opts.index)]];
}
describe(`${testData[0].name} ${testData[0].module}`, () => {
test.each(testData)('$feature -> $description', async (tcData) => {
tcData?.mockFns?.(mock);
Expand Down
10 changes: 7 additions & 3 deletions test/integrations/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { join } from 'path';
import { MockHttpCallsData, TestCaseData } from './testTypes';
import MockAdapter from 'axios-mock-adapter';
import isMatch from 'lodash/isMatch';
import { OptionValues } from 'commander';

export const getTestDataFilePaths = (dirPath: string, destination: string = ''): string[] => {
export const getTestDataFilePaths = (dirPath: string, opts: OptionValues): string[] => {
const globPattern = join(dirPath, '**', 'data.ts');
let testFilePaths = globSync(globPattern);
if (destination) {
testFilePaths = testFilePaths.filter((testFile) => testFile.includes(destination));
if (opts.destination) {
testFilePaths = testFilePaths.filter((testFile) => testFile.includes(opts.destination));
}
if (opts.feature) {
testFilePaths = testFilePaths.filter((testFile) => testFile.includes(opts.feature));
}
return testFilePaths;
};
Expand Down

0 comments on commit 146f1c6

Please sign in to comment.