1
0
Fork 0

Merge pull request #3080 from eriese/eriese-fix-tests

[Fix] Codecov report uploads
This commit is contained in:
Joost De Cock 2022-11-22 15:26:49 +01:00 committed by GitHub
commit a7f38491d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 90 additions and 107 deletions

View file

@ -28,7 +28,7 @@ jobs:
run: npx lerna bootstrap run: npx lerna bootstrap
env: env:
CI: true CI: true
- name: Build all - name: Prebuild Packages
run: npm run buildall run: npx lerna run prebuild
- name: Run eslint - name: Run eslint
run: npm run lint run: npm run lint

View file

@ -34,8 +34,8 @@ jobs:
run: npx lerna bootstrap run: npx lerna bootstrap
env: env:
CI: true CI: true
- name: Build all - name: Prebuild Packages
run: npm run buildall run: npx lerna run prebuild
- name: Run eslint - name: Run eslint
run: | run: |
changed_files="$(git diff --name-only origin/${{ github.base_ref }})" changed_files="$(git diff --name-only origin/${{ github.base_ref }})"

View file

@ -44,7 +44,7 @@ jobs:
- name: Upload to codecov.io - name: Upload to codecov.io
uses: codecov/codecov-action@v3 uses: codecov/codecov-action@v3
with: with:
files: ./packages/core/coverage/coverage-final.json files: ./packages/core/coverage/lcov.info
flags: core flags: core
name: codecov-core name: codecov-core
fail_ci_if_error: true fail_ci_if_error: false

View file

@ -20,7 +20,7 @@ _types:
core: core:
report: 'c8 report' report: 'c8 report'
test: 'c8 mocha tests/*.test.mjs' 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'" prettier: "npx prettier --write 'src/*.mjs' 'tests/*.mjs'"
lint: "npx eslint 'src/*.mjs' 'tests/*.mjs'" lint: "npx eslint 'src/*.mjs' 'tests/*.mjs'"
jsdoc: 'jsdoc -c jsdoc.json -r src' jsdoc: 'jsdoc -c jsdoc.json -r src'
@ -41,6 +41,7 @@ rehype-highlight-lines:
build: '!' build: '!'
mbuild: '!' mbuild: '!'
vbuild: '!' vbuild: '!'
lint: "npx eslint 'src/*.mjs'"
rehype-jargon: rehype-jargon:
lint: "npx eslint 'src/*.mjs'" lint: "npx eslint 'src/*.mjs'"
snapseries: snapseries:

View file

@ -27,7 +27,7 @@
"build": "yarn buildall", "build": "yarn buildall",
"wbuild": "yarn wbuildall", "wbuild": "yarn wbuildall",
"testall": "node scripts/testall.js", "testall": "node scripts/testall.js",
"lint": "lerna run lint -- ", "lint": "lerna run --no-bail lint -- ",
"qa": "yarn qa:prettier && yarn qa:lint", "qa": "yarn qa:prettier && yarn qa:lint",
"qa:prettier": "npx prettier", "qa:prettier": "npx prettier",
"qa:lint": "npx eslint", "qa:lint": "npx eslint",

View file

@ -1,7 +1,6 @@
{ {
"reporter": "html", "reporter": "lcov",
"all": true, "all": true,
"extension": "mjs", "extension": "mjs",
"exclude": ["node_modules/*", "tests"] "exclude": ["node_modules/*", "tests"]
} }

View file

@ -41,7 +41,7 @@
"tips": "node ../../scripts/help.mjs", "tips": "node ../../scripts/help.mjs",
"lint": "npx eslint 'src/*.mjs' 'tests/*.mjs'", "lint": "npx eslint 'src/*.mjs' 'tests/*.mjs'",
"report": "c8 report", "report": "c8 report",
"testci": "mocha tests/*.test.mjs", "testci": "c8 mocha tests/*.test.mjs",
"prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'", "prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'",
"jsdoc": "jsdoc -c jsdoc.json -r src", "jsdoc": "jsdoc -c jsdoc.json -r src",
"cibuild_step0": "node build.mjs", "cibuild_step0": "node build.mjs",

View file

@ -28,7 +28,7 @@
"test": "echo \"rehype-highlight-lines: No tests configured. Perhaps you could write some?\" && exit 0", "test": "echo \"rehype-highlight-lines: No tests configured. Perhaps you could write some?\" && exit 0",
"lab": "cd ../../sites/lab && yarn start", "lab": "cd ../../sites/lab && yarn start",
"tips": "node ../../scripts/help.mjs", "tips": "node ../../scripts/help.mjs",
"lint": "npx eslint 'src/**' 'tests/*.mjs'" "lint": "npx eslint 'src/*.mjs'"
}, },
"peerDependencies": {}, "peerDependencies": {},
"dependencies": { "dependencies": {

View file

@ -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();
});

View file

@ -4,7 +4,6 @@ const spawn = require('child_process').spawn
const projectRoot = path.normalize(path.join(__dirname, '..')) const projectRoot = path.normalize(path.join(__dirname, '..'))
const outputLog = path.join(projectRoot, '.test-failures.log') 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. // Start with a fresh output log on each run.
if (fs.existsSync(outputLog)) { if (fs.existsSync(outputLog)) {
@ -12,21 +11,9 @@ if (fs.existsSync(outputLog)) {
} }
// Run all tests, specifying the collector script. // Run all tests, specifying the collector script.
spawn( spawn('lerna', ['run', '--no-bail', 'testci', '--loglevel', 'error', '--', '--no-warnings'], {
'lerna', stdio: 'inherit',
[ }).on('exit', function (code) {
'run',
'--no-bail',
'testci',
'--loglevel',
'error',
'--',
'--file',
`${collectorScript}`,
'--no-warnings',
],
{ stdio: 'inherit' }
).on('exit', function (code) {
// If a failure occurred, the log file will have been created. Print it. // If a failure occurred, the log file will have been created. Print it.
if (fs.existsSync(outputLog)) { if (fs.existsSync(outputLog)) {
console.error(fs.readFileSync(outputLog, 'utf8').trim()) console.error(fs.readFileSync(outputLog, 'utf8').trim())

View file

@ -16,7 +16,7 @@
}, },
"scripts": { "scripts": {
"dev": "SITE=org node --experimental-json-modules ./node_modules/.bin/next dev -p 8000", "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", "i18n": "SITE=org node ../freesewing.shared/prebuild/i18n-only.mjs",
"build": "next build", "build": "next build",
"cibuild": "yarn prebuild && node --experimental-json-modules ./node_modules/.bin/next build", "cibuild": "yarn prebuild && node --experimental-json-modules ./node_modules/.bin/next build",

View file

@ -1,5 +1,5 @@
import { adult, doll, giant } from '@freesewing/models' import { adult, doll, giant } from '@freesewing/models'
import { getFamily, getShortName } from './config.mjs' import { getShortName } from './config.mjs'
import chai from 'chai' import chai from 'chai'
const expect = chai.expect const expect = chai.expect
@ -15,7 +15,6 @@ const deprecated = ['theo']
* @param boolean log: Set to true to log errors * @param boolean log: Set to true to log errors
*/ */
export const testPatternSampling = (Pattern, log = false) => { export const testPatternSampling = (Pattern, log = false) => {
const pattern = new Pattern()
const config = Pattern.patternConfig const config = Pattern.patternConfig
const design = getShortName(Pattern.designConfig.data.name) const design = getShortName(Pattern.designConfig.data.name)
//const parts = pattern.getPartList() //const parts = pattern.getPartList()
@ -26,23 +25,27 @@ export const testPatternSampling = (Pattern, log = false) => {
pattern.sample().render() pattern.sample().render()
if (log === 'always') { if (log === 'always') {
console.log(pattern.store.logs) 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 return true
} }
if (log && log !== 'always') { if (log && log !== 'always') {
console.log(pattern.settings[pattern.activeSet])
console.log(pattern.store.logs) console.log(pattern.store.logs)
console.log(pattern.setStores[0].logs) console.log(pattern.setStores[pattern.activeSet].logs)
} }
return false return false
} catch (err) { } catch (err) {
if (log && log !== 'always') { if (log && log !== 'always') {
console.log(pattern.settings[0]) console.log(pattern.settings[pattern.activeSet])
console.log(err) console.log(err)
console.log(pattern.store.logs) console.log(pattern.store.logs)
console.log(pattern.setStores[0].logs) console.log(pattern.setStores[pattern.activeSet].logs)
} }
return false return false

View file

@ -1,12 +1,74 @@
const Mocha = require('mocha') 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 // This output very little info and is intended for CI runs
class TerseReporter { class TerseReporter {
constructor(runner) { constructor(runner) {
runner.on(EVENT_TEST_FAIL, (test, err) => { runner.on(EVENT_TEST_FAIL, (test, err) => {
console.log(` FAIL: ${test.fullTitle()}`) // output to the console
console.log(`FAIL: ${test.fullTitle()}`)
console.log(err) 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()
}) })
} }
} }