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

FIX TEST Multiple files cross-contamination extraction #50

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions src/extractor/fileExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,22 @@ export class FileExtractor {
database.createTable(this.serviceName, this.table);
}
}

/**
* Used mainly for testing. When multiple files for the same service are
* processed needs to dump the extractors data between different files.
* @param serviceName
*/
static dumpExtractorData(serviceName: string) {
if (!FileExtractor.registeredExtractors[serviceName]) {
throw new Error(`Extractors for service ${serviceName} do not exist`);
}

// eslint-disable-next-line no-restricted-syntax
for (const extractorEntry of FileExtractor.registeredExtractors[
serviceName
]) {
extractorEntry.extractor.table.rows = [];
}
}
}
24 changes: 16 additions & 8 deletions test/services/zipToSQLite.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as zip from "@zip.js/zip.js";

import { FileExtractor } from "../../src/extractor/fileExtractor";
import { zipToSQLiteInstance } from "../../src/services/zipToSQLite";
import {
deleteFile,
Expand Down Expand Up @@ -56,14 +57,21 @@ describe("services/zipExporter", () => {
expect(fileExists(`zip/${serviceName}/${testFile}.sqlite`)).toBeTruthy();
};

const testPromises: Promise<void>[] = [];
Object.entries(testFiles).forEach((service: [string, string[]]) => {
const serviceName = service[0];
const testFilesForService = service[1];
testFilesForService.forEach((testFile: string) => {
testPromises.push(runTestAgainstFile(serviceName, testFile));
});
});
const testPromises = Object.entries(testFiles).map(
async (service: [string, string[]]) => {
const serviceName = service[0];
const testFilesForService = service[1];

// Extracting data from different zip files of the same service type
// needs to be done in sequence. Extractor table data needs to be
// cleared before another zip file's data get extracted.
// eslint-disable-next-line no-restricted-syntax
for (const testFile of testFilesForService) {
FileExtractor.dumpExtractorData(serviceName);
await runTestAgainstFile(serviceName, testFile);
}
}
);

await Promise.all(testPromises);
});
Expand Down