diff --git a/.github/workflows/lint.all.yml b/.github/workflows/lint.all.yml index 1dba95997d3..5420405c8ef 100644 --- a/.github/workflows/lint.all.yml +++ b/.github/workflows/lint.all.yml @@ -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 diff --git a/.github/workflows/lint.diff.yml b/.github/workflows/lint.diff.yml index b1a1e381d85..9ac4e06dcbb 100644 --- a/.github/workflows/lint.diff.yml +++ b/.github/workflows/lint.diff.yml @@ -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 }})" diff --git a/.github/workflows/tests.all.yml b/.github/workflows/tests.all.yml index 303e999988c..e2021b976b1 100644 --- a/.github/workflows/tests.all.yml +++ b/.github/workflows/tests.all.yml @@ -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 diff --git a/config/scripts.yaml b/config/scripts.yaml index b5c78fc4293..95278c0d388 100644 --- a/config/scripts.yaml +++ b/config/scripts.yaml @@ -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: diff --git a/package.json b/package.json index 8367b1d5451..adf28373469 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/core/.c8rc.json b/packages/core/.c8rc.json index 2d34c12a557..ddda08a8dce 100644 --- a/packages/core/.c8rc.json +++ b/packages/core/.c8rc.json @@ -1,7 +1,6 @@ { - "reporter": "html", + "reporter": "lcov", "all": true, "extension": "mjs", "exclude": ["node_modules/*", "tests"] } - diff --git a/packages/core/package.json b/packages/core/package.json index 5cc0bcd8139..738e3cea774 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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", diff --git a/packages/rehype-highlight-lines/package.json b/packages/rehype-highlight-lines/package.json index f2f6ac4ce0c..09938ee63e9 100644 --- a/packages/rehype-highlight-lines/package.json +++ b/packages/rehype-highlight-lines/package.json @@ -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": { diff --git a/scripts/test-failure-collector.js b/scripts/test-failure-collector.js deleted file mode 100644 index 65f778f2bcd..00000000000 --- a/scripts/test-failure-collector.js +++ /dev/null @@ -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(); -}); diff --git a/scripts/testall.js b/scripts/testall.js index 2df61606b50..139aa90e519 100644 --- a/scripts/testall.js +++ b/scripts/testall.js @@ -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()) diff --git a/sites/org/package.json b/sites/org/package.json index ebafe0e8ce6..616ee789350 100644 --- a/sites/org/package.json +++ b/sites/org/package.json @@ -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", diff --git a/tests/designs/sampling.mjs b/tests/designs/sampling.mjs index 6b103a0679b..c4b833d8a3e 100644 --- a/tests/designs/sampling.mjs +++ b/tests/designs/sampling.mjs @@ -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 diff --git a/tests/reporters/terse.js b/tests/reporters/terse.js index 17adff765db..e7cf9b85dfa 100644 --- a/tests/reporters/terse.js +++ b/tests/reporters/terse.js @@ -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() }) } }