mattermost-mobile/detox/e2e/path_builder.js
Saturnino Abril 6e2549de7f
MM-28653 Detox/E2E: Add jest-junit, jest-html-reporters and pathbuilders for test report/artifacts (#4888)
* add jest-junit, jest-html-reporters and pathbuilders for test report/artifacts

* change optional chaining implementation
2020-10-15 02:27:57 +08:00

24 lines
782 B
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const path = require('path');
const sanitizeFilename = require('sanitize-filename');
const SANITIZE_OPTIONS = {replacement: '_'};
const sanitize = (filename) => sanitizeFilename(filename, SANITIZE_OPTIONS);
class CustomPathBuilder {
constructor({rootDir}) {
this.rootDir = rootDir;
}
buildPathForTestArtifact(artifactName, testSummary = null) {
const fullName = (testSummary && testSummary.fullName) || '';
const segments = [this.rootDir, sanitize(fullName), sanitize(artifactName)];
return path.join(...segments.filter(Boolean));
}
}
module.exports = ({rootDir}) => {
return new CustomPathBuilder({rootDir});
};