testplane
Version:
Tests framework based on mocha and wdio
129 lines • 6.41 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeTests = void 0;
const p_limit_1 = __importDefault(require("p-limit"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const logger = __importStar(require("../../../../utils/logger"));
const utils_1 = require("../utils");
const json_utils_1 = require("../json-utils");
const getUniqTestFiles = async (srcTestPaths) => {
const summaryResult = new Set();
const testPathResults = srcTestPaths.map(() => new Set());
await Promise.all(srcTestPaths.map(async (srcTestPath, idx) => {
if (!fs_extra_1.default.existsSync(srcTestPath)) {
logger.warn(`Skipping "${srcTestPath}" as it does not exist`);
}
const files = await fs_extra_1.default.readdir(srcTestPath);
files.forEach(file => {
const baseFilePath = (0, json_utils_1.stripCompressionSuffix)(file);
summaryResult.add(baseFilePath);
testPathResults[idx].add(baseFilePath);
});
}));
return [summaryResult, testPathResults];
};
const getFullTestPath = (sourceBasePath, preferredCompression) => {
const sourcePath = (0, json_utils_1.getExistingJsonPathWithCompression)(sourceBasePath, preferredCompression).jsonPath;
if (!sourcePath) {
throw new Error([
`Can't merge reports: no suitable source file was found by "${sourceBasePath}" base`,
`It can happen if it was compressed with unsupported compression type, or if the file was removed during command run`,
"If selectivity dump was created with node.js v22+, ensure you are currently is using it too",
].join("\n"));
}
return sourcePath;
};
const mergeJsonTestContents = (testContents) => {
const result = {};
for (const testContent of testContents) {
for (const browserId in testContent) {
result[browserId] ||= {};
for (const dependencyScope in testContent[browserId]) {
result[browserId][dependencyScope] ||= {
css: [],
js: [],
modules: [],
png: [],
};
for (const dependencyType in testContent[browserId][dependencyScope]) {
const depType = dependencyType;
for (const dependency of testContent[browserId][dependencyScope][depType]) {
result[browserId][dependencyScope][depType].push(dependency);
}
}
}
}
}
(0, utils_1.shallowSortObject)(result);
for (const browserId in result) {
(0, utils_1.shallowSortObject)(result[browserId]);
for (const dependencyScope in result[browserId]) {
for (const dependencyType in result[browserId][dependencyScope]) {
const depType = dependencyType;
const depSet = new Set(result[browserId][dependencyScope][depType]);
result[browserId][dependencyScope][depType] = Array.from(depSet).sort((a, b) => a.localeCompare(b));
}
}
}
return result;
};
const mergeTests = async (destPath, selectivitySrcAbsolutePaths, preferredCompression) => {
const selectivityTestsDestPath = (0, utils_1.getSelectivityTestsPath)(destPath);
const srcTestPaths = selectivitySrcAbsolutePaths.map(utils_1.getSelectivityTestsPath);
const [allSrcTests, srcTests] = await getUniqTestFiles(srcTestPaths);
const limited = (0, p_limit_1.default)(32);
const fsPromises = [];
await fs_extra_1.default.ensureDir(selectivityTestsDestPath);
allSrcTests.forEach(fileBase => {
const fileProviders = srcTestPaths.filter((_, idx) => srcTests[idx].has(fileBase));
if (fileProviders.length === 1) {
const sourceBasePath = path_1.default.join(fileProviders[0], fileBase);
const sourcePath = getFullTestPath(sourceBasePath, preferredCompression);
const destinationPath = path_1.default.join(selectivityTestsDestPath, path_1.default.basename(sourcePath));
fsPromises.push(limited(() => fs_extra_1.default.copyFile(sourcePath, destinationPath)));
}
else {
fsPromises.push((async () => {
const testContents = await Promise.all(fileProviders.map(providerPath => {
const sourceBasePath = path_1.default.join(providerPath, fileBase);
return limited(() => (0, json_utils_1.readJsonWithCompression)(sourceBasePath, preferredCompression).catch(cause => {
throw new Error(`Couldn't read "${sourceBasePath}" with compression`, { cause });
}));
}));
const mergedResult = mergeJsonTestContents(testContents);
const destinationBasePath = path_1.default.join(selectivityTestsDestPath, fileBase);
return limited(() => (0, json_utils_1.writeJsonWithCompression)(destinationBasePath, mergedResult, preferredCompression));
})());
}
});
await Promise.all(fsPromises);
};
exports.mergeTests = mergeTests;
//# sourceMappingURL=merge-tests.js.map