Merge pull request #3080 from eriese/eriese-fix-tests
[Fix] Codecov report uploads
This commit is contained in:
commit
a7f38491d4
13 changed files with 90 additions and 107 deletions
4
.github/workflows/lint.all.yml
vendored
4
.github/workflows/lint.all.yml
vendored
|
@ -28,7 +28,7 @@ jobs:
|
|||
run: npx lerna bootstrap
|
||||
env:
|
||||
CI: true
|
||||
- name: Build all
|
||||
run: npm run buildall
|
||||
- name: Prebuild Packages
|
||||
run: npx lerna run prebuild
|
||||
- name: Run eslint
|
||||
run: npm run lint
|
||||
|
|
4
.github/workflows/lint.diff.yml
vendored
4
.github/workflows/lint.diff.yml
vendored
|
@ -34,8 +34,8 @@ jobs:
|
|||
run: npx lerna bootstrap
|
||||
env:
|
||||
CI: true
|
||||
- name: Build all
|
||||
run: npm run buildall
|
||||
- name: Prebuild Packages
|
||||
run: npx lerna run prebuild
|
||||
- name: Run eslint
|
||||
run: |
|
||||
changed_files="$(git diff --name-only origin/${{ github.base_ref }})"
|
||||
|
|
4
.github/workflows/tests.all.yml
vendored
4
.github/workflows/tests.all.yml
vendored
|
@ -44,7 +44,7 @@ jobs:
|
|||
- name: Upload to codecov.io
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
files: ./packages/core/coverage/coverage-final.json
|
||||
files: ./packages/core/coverage/lcov.info
|
||||
flags: core
|
||||
name: codecov-core
|
||||
fail_ci_if_error: true
|
||||
fail_ci_if_error: false
|
||||
|
|
|
@ -20,7 +20,7 @@ _types:
|
|||
core:
|
||||
report: 'c8 report'
|
||||
test: 'c8 mocha tests/*.test.mjs'
|
||||
testci: 'mocha tests/*.test.mjs'
|
||||
testci: 'c8 mocha tests/*.test.mjs'
|
||||
prettier: "npx prettier --write 'src/*.mjs' 'tests/*.mjs'"
|
||||
lint: "npx eslint 'src/*.mjs' 'tests/*.mjs'"
|
||||
jsdoc: 'jsdoc -c jsdoc.json -r src'
|
||||
|
@ -41,6 +41,7 @@ rehype-highlight-lines:
|
|||
build: '!'
|
||||
mbuild: '!'
|
||||
vbuild: '!'
|
||||
lint: "npx eslint 'src/*.mjs'"
|
||||
rehype-jargon:
|
||||
lint: "npx eslint 'src/*.mjs'"
|
||||
snapseries:
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
"build": "yarn buildall",
|
||||
"wbuild": "yarn wbuildall",
|
||||
"testall": "node scripts/testall.js",
|
||||
"lint": "lerna run lint -- ",
|
||||
"lint": "lerna run --no-bail lint -- ",
|
||||
"qa": "yarn qa:prettier && yarn qa:lint",
|
||||
"qa:prettier": "npx prettier",
|
||||
"qa:lint": "npx eslint",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"reporter": "html",
|
||||
"reporter": "lcov",
|
||||
"all": true,
|
||||
"extension": "mjs",
|
||||
"exclude": ["node_modules/*", "tests"]
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
"tips": "node ../../scripts/help.mjs",
|
||||
"lint": "npx eslint 'src/*.mjs' 'tests/*.mjs'",
|
||||
"report": "c8 report",
|
||||
"testci": "mocha tests/*.test.mjs",
|
||||
"testci": "c8 mocha tests/*.test.mjs",
|
||||
"prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'",
|
||||
"jsdoc": "jsdoc -c jsdoc.json -r src",
|
||||
"cibuild_step0": "node build.mjs",
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"test": "echo \"rehype-highlight-lines: No tests configured. Perhaps you could write some?\" && exit 0",
|
||||
"lab": "cd ../../sites/lab && yarn start",
|
||||
"tips": "node ../../scripts/help.mjs",
|
||||
"lint": "npx eslint 'src/**' 'tests/*.mjs'"
|
||||
"lint": "npx eslint 'src/*.mjs'"
|
||||
},
|
||||
"peerDependencies": {},
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Used to collect test failures in a file. Use by specifying --file to Mocha.
|
||||
*
|
||||
* See https://mochajs.org/#command-line-usage
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const projectRoot = path.normalize(path.join(__dirname, '..'));
|
||||
const outputLog = path.join(projectRoot, '.test-failures.log');
|
||||
|
||||
const red = function(string) {
|
||||
return `\x1b[31m${string}\x1b[0m`;
|
||||
};
|
||||
|
||||
const green = function(string) {
|
||||
return `\x1b[32m${string}\x1b[0m`;
|
||||
};
|
||||
|
||||
const dim = function(string) {
|
||||
return `\x1b[2m${string}\x1b[0m`;
|
||||
};
|
||||
|
||||
// Mapping of test file name to array of failing tests.
|
||||
const failuresPerFile = {};
|
||||
|
||||
afterEach(function () {
|
||||
if (this.currentTest.state === "failed") {
|
||||
failuresPerFile[this.currentTest.file] = failuresPerFile[this.currentTest.file] || [];
|
||||
failuresPerFile[this.currentTest.file].push(this.currentTest);
|
||||
}
|
||||
});
|
||||
|
||||
after(function () {
|
||||
if (Object.keys(failuresPerFile).length === 0) return;
|
||||
|
||||
const fs = require('fs')
|
||||
const logger = fs.createWriteStream(outputLog, { flags: 'a' });
|
||||
const writeLine = (line) => logger.write(`${line}\n`);
|
||||
|
||||
for (let file in failuresPerFile) {
|
||||
const failures = failuresPerFile[file];
|
||||
|
||||
// Remove project root from file path to keep log lines shorter.
|
||||
if (file.startsWith(projectRoot)) {
|
||||
file = file.substr(projectRoot.length + 1, file.length - projectRoot.length - 1)
|
||||
}
|
||||
|
||||
// Print each failure.
|
||||
failures.forEach(function (failure, i) {
|
||||
const stack = failure.err.stack.split('\n');
|
||||
writeLine(`${file}: ${i + 1}\) ${failure.title}:`);
|
||||
writeLine(`${file}:`);
|
||||
writeLine(`${file}: ${red(stack[0].trim())}`);
|
||||
writeLine(`${file}: ${green('+ expected')} ${red('- actual')}`);
|
||||
writeLine(`${file}:`);
|
||||
writeLine(`${file}: ${red("-" + failure.err.actual)}`);
|
||||
writeLine(`${file}: ${green("+" + failure.err.expected)}`);
|
||||
writeLine(`${file}:`);
|
||||
stack.slice(1).forEach(function (stackLine) {
|
||||
writeLine(`${file}: ${dim(stackLine.trim())}`);
|
||||
});
|
||||
if (i < failures.length - 1) {
|
||||
writeLine(`${file}:`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
logger.end();
|
||||
});
|
|
@ -4,7 +4,6 @@ const spawn = require('child_process').spawn
|
|||
|
||||
const projectRoot = path.normalize(path.join(__dirname, '..'))
|
||||
const outputLog = path.join(projectRoot, '.test-failures.log')
|
||||
const collectorScript = path.join(projectRoot, 'scripts', 'test-failure-collector.js')
|
||||
|
||||
// Start with a fresh output log on each run.
|
||||
if (fs.existsSync(outputLog)) {
|
||||
|
@ -12,21 +11,9 @@ if (fs.existsSync(outputLog)) {
|
|||
}
|
||||
|
||||
// Run all tests, specifying the collector script.
|
||||
spawn(
|
||||
'lerna',
|
||||
[
|
||||
'run',
|
||||
'--no-bail',
|
||||
'testci',
|
||||
'--loglevel',
|
||||
'error',
|
||||
'--',
|
||||
'--file',
|
||||
`${collectorScript}`,
|
||||
'--no-warnings',
|
||||
],
|
||||
{ stdio: 'inherit' }
|
||||
).on('exit', function (code) {
|
||||
spawn('lerna', ['run', '--no-bail', 'testci', '--loglevel', 'error', '--', '--no-warnings'], {
|
||||
stdio: 'inherit',
|
||||
}).on('exit', function (code) {
|
||||
// If a failure occurred, the log file will have been created. Print it.
|
||||
if (fs.existsSync(outputLog)) {
|
||||
console.error(fs.readFileSync(outputLog, 'utf8').trim())
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"dev": "SITE=org node --experimental-json-modules ./node_modules/.bin/next dev -p 8000",
|
||||
"prebuild": "SITE=org node ../freesewing.shared/prebuild/index.mjs",
|
||||
"prebuild": "SITE=org node ../shared/prebuild/index.mjs",
|
||||
"i18n": "SITE=org node ../freesewing.shared/prebuild/i18n-only.mjs",
|
||||
"build": "next build",
|
||||
"cibuild": "yarn prebuild && node --experimental-json-modules ./node_modules/.bin/next build",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { adult, doll, giant } from '@freesewing/models'
|
||||
import { getFamily, getShortName } from './config.mjs'
|
||||
import { getShortName } from './config.mjs'
|
||||
import chai from 'chai'
|
||||
|
||||
const expect = chai.expect
|
||||
|
@ -15,7 +15,6 @@ const deprecated = ['theo']
|
|||
* @param boolean log: Set to true to log errors
|
||||
*/
|
||||
export const testPatternSampling = (Pattern, log = false) => {
|
||||
const pattern = new Pattern()
|
||||
const config = Pattern.patternConfig
|
||||
const design = getShortName(Pattern.designConfig.data.name)
|
||||
//const parts = pattern.getPartList()
|
||||
|
@ -26,23 +25,27 @@ export const testPatternSampling = (Pattern, log = false) => {
|
|||
pattern.sample().render()
|
||||
if (log === 'always') {
|
||||
console.log(pattern.store.logs)
|
||||
console.log(pattern.setStores[0].logs)
|
||||
console.log(pattern.setStores[pattern.activeSet].logs)
|
||||
}
|
||||
if (pattern.store.logs.error.length < 1 && pattern.setStores[0].logs.error.length < 1) {
|
||||
if (
|
||||
pattern.store.logs.error.length < 1 &&
|
||||
pattern.setStores[pattern.activeSet].logs.error.length < 1
|
||||
) {
|
||||
return true
|
||||
}
|
||||
if (log && log !== 'always') {
|
||||
console.log(pattern.settings[pattern.activeSet])
|
||||
console.log(pattern.store.logs)
|
||||
console.log(pattern.setStores[0].logs)
|
||||
console.log(pattern.setStores[pattern.activeSet].logs)
|
||||
}
|
||||
|
||||
return false
|
||||
} catch (err) {
|
||||
if (log && log !== 'always') {
|
||||
console.log(pattern.settings[0])
|
||||
console.log(pattern.settings[pattern.activeSet])
|
||||
console.log(err)
|
||||
console.log(pattern.store.logs)
|
||||
console.log(pattern.setStores[0].logs)
|
||||
console.log(pattern.setStores[pattern.activeSet].logs)
|
||||
}
|
||||
|
||||
return false
|
||||
|
|
|
@ -1,12 +1,74 @@
|
|||
const Mocha = require('mocha')
|
||||
const { EVENT_TEST_FAIL } = Mocha.Runner.constants
|
||||
const { EVENT_TEST_FAIL, EVENT_RUN_END } = Mocha.Runner.constants
|
||||
|
||||
const path = require('path')
|
||||
const projectRoot = path.normalize(path.join(__dirname, '..'))
|
||||
const outputLog = path.join(projectRoot, '.test-failures.log')
|
||||
|
||||
const red = function (string) {
|
||||
return `\x1b[31m${string}\x1b[0m`
|
||||
}
|
||||
|
||||
const green = function (string) {
|
||||
return `\x1b[32m${string}\x1b[0m`
|
||||
}
|
||||
|
||||
const dim = function (string) {
|
||||
return `\x1b[2m${string}\x1b[0m`
|
||||
}
|
||||
|
||||
// Mapping of test file name to array of failing tests.
|
||||
const failuresPerFile = {}
|
||||
|
||||
// This output very little info and is intended for CI runs
|
||||
class TerseReporter {
|
||||
constructor(runner) {
|
||||
runner.on(EVENT_TEST_FAIL, (test, err) => {
|
||||
console.log(` FAIL: ${test.fullTitle()}`)
|
||||
// output to the console
|
||||
console.log(`FAIL: ${test.fullTitle()}`)
|
||||
console.log(err)
|
||||
|
||||
// save for adding to an output file
|
||||
failuresPerFile[this.currentTest.file] = failuresPerFile[this.currentTest.file] || []
|
||||
failuresPerFile[this.currentTest.file].push(this.currentTest)
|
||||
})
|
||||
|
||||
runner.on(EVENT_RUN_END, () => {
|
||||
if (Object.keys(failuresPerFile).length === 0) return
|
||||
|
||||
const fs = require('fs')
|
||||
const logger = fs.createWriteStream(outputLog, { flags: 'a' })
|
||||
const writeLine = (line) => logger.write(`${line}\n`)
|
||||
|
||||
for (let file in failuresPerFile) {
|
||||
const failures = failuresPerFile[file]
|
||||
|
||||
// Remove project root from file path to keep log lines shorter.
|
||||
if (file.startsWith(projectRoot)) {
|
||||
file = file.substr(projectRoot.length + 1, file.length - projectRoot.length - 1)
|
||||
}
|
||||
|
||||
// Print each failure.
|
||||
failures.forEach(function (failure, i) {
|
||||
const stack = failure.err.stack.split('\n')
|
||||
writeLine(`${file}: ${i + 1}) ${failure.title}:`)
|
||||
writeLine(`${file}:`)
|
||||
writeLine(`${file}: ${red(stack[0].trim())}`)
|
||||
writeLine(`${file}: ${green('+ expected')} ${red('- actual')}`)
|
||||
writeLine(`${file}:`)
|
||||
writeLine(`${file}: ${red('-' + failure.err.actual)}`)
|
||||
writeLine(`${file}: ${green('+' + failure.err.expected)}`)
|
||||
writeLine(`${file}:`)
|
||||
stack.slice(1).forEach(function (stackLine) {
|
||||
writeLine(`${file}: ${dim(stackLine.trim())}`)
|
||||
})
|
||||
if (i < failures.length - 1) {
|
||||
writeLine(`${file}:`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
logger.end()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue