@testomatio/reporter
Advanced tools
Comparing version 1.0.17 to 1.0.18-beta.1
<!-- pending release updates --> | ||
# 1.0.18 | ||
* Fixed stack traces for CodeceptJS | ||
# 1.0.17 | ||
@@ -3,0 +7,0 @@ |
const debug = require('debug')('@testomatio/reporter:adapter:codeceptjs'); | ||
const chalk = require('chalk'); | ||
const TestomatClient = require('../client'); | ||
const { STATUS, APP_PREFIX, TESTOMAT_TMP_STORAGE } = require('../constants'); | ||
const { STATUS, APP_PREFIX, TESTOMAT_TMP_STORAGE_DIR } = require('../constants'); | ||
const upload = require('../fileUploader'); | ||
@@ -59,3 +59,3 @@ const { parseTest: getIdFromTestTitle, fileSystem } = require('../utils/utils'); | ||
// clear tmp dir | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE.mainDir); | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR); | ||
@@ -151,5 +151,2 @@ recorder.add('Creating new run', () => client.createRun()); | ||
const testObj = getTestAndMessage(title); | ||
if (error && error.stack && test.steps && test.steps.length) { | ||
error.stack = test.steps[test.steps.length - 1].line(); | ||
} | ||
@@ -156,0 +153,0 @@ const files = []; |
@@ -5,5 +5,5 @@ // eslint-disable-next-line global-require, import/no-extraneous-dependencies, import/no-unresolved | ||
const fs = require('fs'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE } = require('../../constants'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../../constants'); | ||
const TestomatClient = require('../../client'); | ||
const logger = require('../../logger'); | ||
const logger = require('../../storages/logger'); | ||
const { parseTest, fileSystem } = require('../../utils/utils'); | ||
@@ -41,3 +41,3 @@ | ||
if (envelope.testRunStarted) { | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE.mainDir); | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR); | ||
} | ||
@@ -44,0 +44,0 @@ if (envelope.testCaseStarted && this.client) { |
@@ -5,3 +5,3 @@ // eslint-disable-next-line global-require, import/no-extraneous-dependencies, import/no-unresolved | ||
const { parseTest, fileSystem } = require('../../utils/utils'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE } = require('../../constants'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../../constants'); | ||
const TestomatClient = require('../../client'); | ||
@@ -101,3 +101,3 @@ | ||
options.eventBroadcaster.on('test-run-started', () => { | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE.mainDir); | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR); | ||
this?.client?.createRun(); | ||
@@ -104,0 +104,0 @@ }); |
const TestomatClient = require('../client'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE } = require('../constants'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../constants'); | ||
const { parseTest, ansiRegExp, fileSystem } = require('../utils/utils'); | ||
@@ -14,16 +14,5 @@ | ||
static getIdOfCurrentlyRunningTest() { | ||
if (!process.env.JEST_WORKER_ID) return null; | ||
try { | ||
// @ts-expect-error "expect" could only be defined inside Jest environement (forbidden to import it outside) | ||
// eslint-disable-next-line no-undef | ||
if (expect && expect?.getState()?.currentTestName) return parseTest(expect?.getState()?.currentTestName); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
onRunStart() { | ||
// clear tmp dir | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE.mainDir); | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR); | ||
} | ||
@@ -76,5 +65,2 @@ | ||
this.client.updateRunStatus(status); | ||
// clear tmp dir | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE.mainDir); | ||
} | ||
@@ -81,0 +67,0 @@ } |
// eslint-disable-next-line global-require, import/no-extraneous-dependencies | ||
const Mocha = require('mocha'); | ||
const debug = require('debug')('@testomatio/reporter:adapter:mocha'); | ||
const chalk = require('chalk'); | ||
const TestomatClient = require('../client'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE } = require('../constants'); | ||
const { parseTest, specificTestInfo, fileSystem } = require('../utils/utils'); | ||
const ArtifactStorage = require('../_ArtifactStorageOld'); | ||
const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../constants'); | ||
const { parseTest, fileSystem } = require('../utils/utils'); | ||
@@ -18,3 +16,3 @@ const { EVENT_RUN_BEGIN, EVENT_RUN_END, EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING } = | ||
let skipped = 0; | ||
let artifactStore; | ||
// let artifactStore; | ||
@@ -28,9 +26,3 @@ const apiKey = opts?.reporterOptions?.apiKey || process.env.TESTOMATIO; | ||
const params = { | ||
toFile: true, | ||
}; | ||
artifactStore = runner._workerReporter !== undefined ? new ArtifactStorage(params) : new ArtifactStorage(); | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE.mainDir); | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR); | ||
}); | ||
@@ -43,16 +35,7 @@ | ||
const specificTest = specificTestInfo(test); | ||
const content = await artifactStore.artifactByTestName(specificTest); | ||
debug(`test=${specificTest} content = `, content); | ||
client.addTestRun( | ||
STATUS.PASSED, | ||
{ | ||
test_id: testId, | ||
title: test.title, | ||
time: test.duration, | ||
}, | ||
content, | ||
); | ||
client.addTestRun(STATUS.PASSED, { | ||
test_id: testId, | ||
title: test.title, | ||
time: test.duration, | ||
}); | ||
}); | ||
@@ -76,17 +59,8 @@ | ||
const specificTest = specificTestInfo(test); | ||
const content = await artifactStore.artifactByTestName(specificTest); | ||
debug(`fail test=${specificTest} content = `, content); | ||
client.addTestRun( | ||
STATUS.FAILED, | ||
{ | ||
error: err, | ||
test_id: testId, | ||
title: test.title, | ||
time: test.duration, | ||
}, | ||
content, | ||
); | ||
client.addTestRun(STATUS.FAILED, { | ||
error: err, | ||
test_id: testId, | ||
title: test.title, | ||
time: test.duration, | ||
}); | ||
}); | ||
@@ -98,4 +72,2 @@ | ||
client.updateRunStatus(status); | ||
artifactStore.cleanup(); | ||
}); | ||
@@ -102,0 +74,0 @@ } |
@@ -6,3 +6,3 @@ const chalk = require('chalk'); | ||
const fs = require('fs'); | ||
const { APP_PREFIX, STATUS: Status, TESTOMAT_TMP_STORAGE } = require('../constants'); | ||
const { APP_PREFIX, STATUS: Status, TESTOMAT_TMP_STORAGE_DIR } = require('../constants'); | ||
const TestomatioClient = require('../client'); | ||
@@ -23,3 +23,3 @@ const { isArtifactsEnabled } = require('../fileUploader'); | ||
// clean data storage | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE.mainDir); | ||
fileSystem.clearDir(TESTOMAT_TMP_STORAGE_DIR); | ||
if (!this.client) return; | ||
@@ -30,5 +30,7 @@ this.suite = suite; | ||
// onTestBegin(test) { | ||
// const testId = parseTest(test.title); | ||
// } | ||
/* | ||
onTestBegin(test) { | ||
// does not work; value is not to the storage context | ||
global.testTitle = test.title; | ||
} */ | ||
@@ -50,19 +52,29 @@ onTestEnd(test, result) { | ||
const logs = `\n\n${chalk.bold('Logs:')}\n${chalk.red(result.stderr.join(''))}\n${result.stdout.join('')}`; | ||
let logs = ''; | ||
if (result.stderr.length || result.stdout.length) { | ||
logs = `\n\n${chalk.bold('Logs:')}\n${chalk.red(result.stderr.join(''))}\n${result.stdout.join('')}`; | ||
} | ||
const reportTestPromise = this.client.addTestRun(checkStatus(result.status), { | ||
error, | ||
test_id: testId, | ||
suite_title, | ||
title, | ||
steps: steps.join('\n'), | ||
time: duration, | ||
stack: logs, | ||
}).then(pipes => { | ||
testId = pipes?.filter(p => p.pipe.includes('Testomatio'))[0]?.result?.data?.test_id; | ||
const reportTestPromise = this.client | ||
.addTestRun(checkStatus(result.status), { | ||
error, | ||
test_id: testId, | ||
suite_title, | ||
title, | ||
steps: steps.join('\n'), | ||
time: duration, | ||
stack: logs, | ||
}) | ||
.then(pipes => { | ||
testId = pipes?.filter(p => p.pipe.includes('Testomatio'))[0]?.result?.data?.test_id; | ||
this.uploads.push({ | ||
testId, title, suite_title, files: result.attachments.filter((a) => a.body || a.path) | ||
this.uploads.push({ | ||
testId, | ||
title, | ||
suite_title, | ||
files: result.attachments.filter(a => a.body || a.path), | ||
}); | ||
// remove empty uploads | ||
this.uploads = this.uploads.filter(upload => upload.files.length); | ||
}); | ||
}); | ||
@@ -69,0 +81,0 @@ reportTestPromises.push(reportTestPromise); |
@@ -56,2 +56,8 @@ #!/usr/bin/env node | ||
if (!command.split) { | ||
process.exitCode = 255; | ||
console.log(APP_PREFIX, `No command provided. Use -c option to launch a test runner.`); | ||
return; | ||
} | ||
const client = new TestomatClient({ apiKey, title, parallel: true }); | ||
@@ -78,8 +84,2 @@ | ||
if (!command.split) { | ||
process.exitCode = 255; | ||
console.log(APP_PREFIX, `No command provided. Use -c option to launch a test runner.`); | ||
return; | ||
} | ||
const testCmds = command.split(' '); | ||
@@ -86,0 +86,0 @@ console.log(APP_PREFIX, `🚀 Running`, chalk.green(command)); |
@@ -11,2 +11,3 @@ const debug = require('debug')('@testomatio/reporter:client'); | ||
const pipesFactory = require('./pipe'); | ||
const artifactStorage = require('./storages/artifact-storage'); | ||
@@ -100,5 +101,2 @@ /** | ||
global.testomatioArtifacts = []; | ||
if (!global.testomatioDataStore) global.testomatioDataStore = {}; | ||
this.queue = this.queue | ||
@@ -117,7 +115,5 @@ .then(() => Promise.all(this.pipes.map(p => p.createRun()))) | ||
* @param {TestData} [testData] | ||
* @param {string[]} [storeArtifacts] | ||
* @returns {Promise<PipeResult[]>} | ||
*/ | ||
async addTestRun(status, testData, storeArtifacts = []) { | ||
debug('Adding test run for test', testData?.test_id || 'unknown test'); | ||
async addTestRun(status, testData) { | ||
// all pipes disabled, skipping | ||
@@ -161,4 +157,5 @@ if (!this.pipes?.filter(p => p.isEnabled).length) return []; | ||
// ATTACH LOGS from storage | ||
// in some cases (e.g. using cucumber) logger instance becomes empty object, if import at the top of the file | ||
const logger = require('./logger'); | ||
const logger = require('./storages/logger'); | ||
const testLogs = logger.getLogs(test_id); | ||
@@ -169,12 +166,9 @@ // debug(`Test logs for ${test_id}:\n`, testLogs); | ||
if (Array.isArray(storeArtifacts) && storeArtifacts.length) { | ||
debug('CLIENT storeArtifact', storeArtifacts); | ||
files.push(...storeArtifacts); | ||
} | ||
// GET ARTIFACTS from storage | ||
const artifactFiles = artifactStorage.get(test_id); | ||
if (artifactFiles) files.push(...artifactFiles); | ||
if (Array.isArray(global.testomatioArtifacts)) { | ||
debug('CLIENT global[testomatioArtifacts]', global.testomatioArtifacts); | ||
files.push(...global.testomatioArtifacts); | ||
global.testomatioArtifacts = []; | ||
} | ||
// GET KEY-VALUEs from storage | ||
const keyValueStorage = require('./storages/key-value-storage'); | ||
const keyValues = keyValueStorage.get(test_id); | ||
@@ -192,3 +186,3 @@ for (const file of files) { | ||
global.testomatioArtifacts = []; | ||
// global.testomatioArtifacts = []; | ||
@@ -211,2 +205,3 @@ this.totalUploaded += uploadedFiles.filter(n => n).length; | ||
artifacts, | ||
meta: keyValues, | ||
}; | ||
@@ -247,10 +242,12 @@ | ||
.then(() => { | ||
debug('TOTAL uploaded files', this.totalUploaded); | ||
debug('TOTAL artifacts', this.totalUploaded); | ||
if (this.totalUploaded && !upload.isArtifactsEnabled()) | ||
debug(`${this.totalUploaded} artifacts are not uploaded, because artifacts uploading is not enabled`); | ||
if (upload.isArtifactsEnabled() && this.totalUploaded > 0) { | ||
if (this.totalUploaded && upload.isArtifactsEnabled()) { | ||
console.log( | ||
APP_PREFIX, | ||
`🗄️ Total ${this.totalUploaded} artifacts ${ | ||
`🗄️ ${this.totalUploaded} artifacts ${ | ||
process.env.TESTOMATIO_PRIVATE_ARTIFACTS ? 'privately' : chalk.bold('publicly') | ||
} uploaded to S3 bucket `, | ||
} uploaded to S3 bucket`, | ||
); | ||
@@ -257,0 +254,0 @@ } |
const chalk = require('chalk'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
const APP_PREFIX = chalk.gray('[TESTOMATIO]'); | ||
const TESTOMAT_ARTIFACT_SUFFIX = "testomatio_artifact_"; | ||
const TESTOMAT_TMP_STORAGE = { | ||
mainDir: "testomatio_tmp", | ||
} | ||
const TESTOMAT_TMP_STORAGE_DIR = path.join(os.tmpdir(), 'testomatio_tmp'); | ||
@@ -27,6 +26,5 @@ const CSV_HEADERS = [ | ||
APP_PREFIX, | ||
TESTOMAT_ARTIFACT_SUFFIX, | ||
TESTOMAT_TMP_STORAGE, | ||
TESTOMAT_TMP_STORAGE_DIR, | ||
CSV_HEADERS, | ||
STATUS, | ||
} |
@@ -1,8 +0,8 @@ | ||
const logger = require('./logger'); | ||
const logger = require('./storages/logger'); | ||
const TestomatClient = require('./client'); | ||
const TRConstants = require('./constants'); | ||
const TRArtifacts = require('./_ArtifactStorageOld'); | ||
const log = logger.templateLiteralLog.bind(logger); | ||
const step = logger.step.bind(logger); | ||
const reporterFunctions = require('./reporter-functions'); | ||
@@ -16,4 +16,9 @@ module.exports = { | ||
TRConstants, | ||
TRArtifacts, | ||
addArtifact: TRArtifacts.artifact, | ||
}; | ||
module.exports.testomat = { | ||
artifact: reporterFunctions.artifact, | ||
log: reporterFunctions.log, | ||
step: reporterFunctions.step, | ||
meta: reporterFunctions.keyValue, | ||
}; |
@@ -293,2 +293,15 @@ const { URL } = require('url'); | ||
const jestHelpers = { | ||
getIdOfCurrentlyRunningTest: () => { | ||
if (!process.env.JEST_WORKER_ID) return null; | ||
try { | ||
// @ts-expect-error "expect" could only be defined inside Jest environement (forbidden to import it outside) | ||
// eslint-disable-next-line no-undef | ||
if (expect && expect?.getState()?.currentTestName) return parseTest(expect?.getState()?.currentTestName); | ||
} catch (e) { | ||
return null; | ||
} | ||
}, | ||
}; | ||
module.exports = { | ||
@@ -303,2 +316,3 @@ isSameTest, | ||
getCurrentDateTime, | ||
jestHelpers, | ||
specificTestInfo, | ||
@@ -305,0 +319,0 @@ isValidUrl, |
{ | ||
"name": "@testomatio/reporter", | ||
"version": "1.0.17", | ||
"version": "1.0.18-beta.1", | ||
"description": "Testomatio Reporter Client", | ||
@@ -5,0 +5,0 @@ "main": "./lib/reporter.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
164765
40
4057
88
2