diff --git a/config/changelog.yaml b/config/changelog.yaml index 21c28afa217..52655023885 100644 --- a/config/changelog.yaml +++ b/config/changelog.yaml @@ -3,6 +3,54 @@ unreleased: Added: core: - Added the new attributes.setIfUnset() method + plugin-banner: + - Added (esm) unit tests + plugin-bartack: + - Added (esm) unit tests + plugin-bundle: + - Added (esm) unit tests + plugin-bust: + - Added (esm) unit tests + plugin-buttons: + - Added (esm) unit tests + plugin-cutonfold: + - Added (esm) unit tests + plugin-dimension: + - Added (esm) unit tests + plugin-export-dxf: + - Added (esm) unit tests + plugin-flip: + - Added (esm) unit tests + plugin-gore: + - Added (esm) unit tests + plugin-grainline: + - Added (esm) unit tests + plugin-i18n: + - Added (esm) unit tests + plugin-logo: + - Added (esm) unit tests + plugin-measurements: + - Added (esm) unit tests + plugin-mirror: + - Added (esm) unit tests + plugin-notches: + - Added (esm) unit tests + plugin-round: + - Added (esm) unit tests + plugin-scalebox: + - Added (esm) unit tests + plugin-sprinkle: + - Added (esm) unit tests + plugin-svgattr: + - Added (esm) unit tests + plugin-theme: + - Added (esm) unit tests + plugin-title: + - Added (esm) unit tests + plugin-validate: + - Added (esm) unit tests + plugin-versionfree-svg: + - Added (esm) unit tests Fixed: plugin-buttons: diff --git a/config/dependencies.yaml b/config/dependencies.yaml index 41daeddf07f..ee3e919ce44 100644 --- a/config/dependencies.yaml +++ b/config/dependencies.yaml @@ -29,13 +29,16 @@ _types: 'axios': &axios '0.21.2' 'react-intl': &react-intl '^5.17.6' 'prop-types': '^15.7.2' - 'mocha': '^9.1.1' - 'chai': '^4.2.0' - 'chai-string': '^1.5.0' - '@babel/register': '^7.10.5' + 'mocha': &mocha '^9.1.1' + 'chai': &chai '^4.2.0' + '@babel/register': &babelregister '^7.10.5' plugin: peer: '@freesewing/core': *freesewing + dev: + 'mocha': *mocha + 'chai': *chai + '@babel/register': *babelregister aaron: peer: '@freesewing/brian': *freesewing diff --git a/config/scripts.yaml b/config/scripts.yaml index 240ff655e82..ca3e685bddf 100644 --- a/config/scripts.yaml +++ b/config/scripts.yaml @@ -10,11 +10,12 @@ _: _types: pattern: netlify: 'echo "Not configured yet"' - test: 'BABEL_ENV=production ../../node_modules/.bin/_mocha tests/*.test.js --require @babel/register' - testci: 'BABEL_ENV=production ./node_modules/.bin/_mocha tests/*.test.js --require @babel/register' + test: 'BABEL_ENV=production ../../node_modules/.bin/_mocha tests/*.test.mjs --require @babel/register' + testci: 'BABEL_ENV=production ./node_modules/.bin/_mocha tests/*.test.mjs --require @babel/register' plugin: - test: 'BABEL_ENV=production ../../node_modules/.bin/_mocha tests/*.test.js --require @babel/register' - prettier: "npx prettier --write 'src/*.js' 'tests/*.js'" + test: 'BABEL_ENV=production ../../node_modules/.bin/_mocha tests/*.test.mjs --require @babel/register' + testci: 'BABEL_ENV=production ../../node_modules/.bin/_mocha tests/*.test.mjs --require @babel/register' + prettier: "npx prettier --write 'src/*.js' 'tests/*.mjs'" create-freesewing-pattern: clean: '!' nodebuild: '!' diff --git a/config/templates/tests/patterns/shared.test.js.template b/config/templates/tests/patterns/shared.test.mjs.template similarity index 50% rename from config/templates/tests/patterns/shared.test.js.template rename to config/templates/tests/patterns/shared.test.mjs.template index dae0e9c87e0..5fe7f121187 100644 --- a/config/templates/tests/patterns/shared.test.js.template +++ b/config/templates/tests/patterns/shared.test.mjs.template @@ -1,15 +1,17 @@ // This file is auto-generated. // Changes you make will be overwritten. -const expect = require("chai").expect; -const models = require("@freesewing/models") -const patterns = require("@freesewing/pattern-info") - -const {{ Pattern }} = require('../dist') +import chai from 'chai' +import models from '@freesewing/models' +import patterns from '@freesewing/pattern-info' +import {{ Pattern }} from '../dist/index.mjs' // Shared tests -const testPatternConfig = require('../../../tests/patterns/config') -const testPatternDrafting = require('../../../tests/patterns/drafting') -const testPatternSampling = require('../../../tests/patterns/sampling') +import { testPatternConfig } from '../../../tests/patterns/config.mjs' +import { testPatternDrafting } from '../../../tests/patterns/drafting.mjs' +import { testPatternSampling } from '../../../tests/patterns/sampling.mjs' + +const expect = chai.expect + // Test config testPatternConfig( diff --git a/config/templates/tests/plugins/shared.test.mjs.template b/config/templates/tests/plugins/shared.test.mjs.template new file mode 100644 index 00000000000..42cd98f4655 --- /dev/null +++ b/config/templates/tests/plugins/shared.test.mjs.template @@ -0,0 +1,10 @@ +// This file is auto-generated. +// Changes you make will be overwritten. +import freesewing from '@freesewing/core' +import chai from 'chai' +import plugin from '../dist/index.mjs' +import { sharedPluginTests } from '../../../tests/plugins/shared.mjs' + + +// Run shared tests +sharedPluginTests(plugin, freesewing, chai.expect) diff --git a/config/templates/workflows/tests.pattern.yml b/config/templates/workflows/tests.pattern.yml index c978645df34..f2bc3cf612d 100644 --- a/config/templates/workflows/tests.pattern.yml +++ b/config/templates/workflows/tests.pattern.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: - node-version: [12.x] + node-version: [14.x] {{=<% %>=}} steps: diff --git a/config/templates/workflows/tests.plugin.yml b/config/templates/workflows/tests.plugin.yml new file mode 100644 index 00000000000..7875b251468 --- /dev/null +++ b/config/templates/workflows/tests.plugin.yml @@ -0,0 +1,42 @@ +name: Unit tests - {{ Plugin }} + +on: + push: + branches: + - develop + - main + pull_request: + branches: + - develop + - main + +jobs: + test: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x] + +{{=<% %>=}} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} +<%={{ }}=%> + - name: Install dependencies + run: cd packages/{{ pattern }} && npm install + env: + CI: true + - name: Install peer & test dependencies + run: "cd packages/{{ plugin }} && npm install {{{ peerdeps }}} @freesewing/models@{{{ version }}} @freesewing/pattern-info@{{{ version }}} mocha chai" + env: + CI: true + - name: Build plugin + run: cd packages/{{ plugin }} && npm run build + - name: Run plugin unit tests + run: cd packages/{{ plugin }} && npm run testci diff --git a/tests/patterns/config.js b/tests/patterns/config.mjs similarity index 98% rename from tests/patterns/config.js rename to tests/patterns/config.mjs index a8d5d716ae0..3529b87e74d 100644 --- a/tests/patterns/config.js +++ b/tests/patterns/config.mjs @@ -20,7 +20,7 @@ const deprecated = ['theo'] * @param object models: Imported @freesewing/models * @param object patterns: Imported @freesewing/pattern-info */ -const testPatternConfig = (design, pattern, expect, models, patterns) => { +export const testPatternConfig = (design, pattern, expect, models, patterns) => { it('Metadata:', () => true) it(` - 'name' should match package name`, () => { expect(pattern.config.name).to.equal(design) @@ -199,4 +199,3 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => { } } -module.exports = testPatternConfig diff --git a/tests/patterns/drafting.js b/tests/patterns/drafting.mjs similarity index 95% rename from tests/patterns/drafting.js rename to tests/patterns/drafting.mjs index ad8aa438156..db6453556dd 100644 --- a/tests/patterns/drafting.js +++ b/tests/patterns/drafting.mjs @@ -1,4 +1,4 @@ -const nonHumanMeasurements = require('./non-human-measurements.js') +import { nonHumanMeasurements } from './non-human-measurements.mjs' // Some patterns are different const isGarment = design => ([ @@ -22,7 +22,7 @@ const deprecated = ['theo'] * @param object models: Imported @freesewing/models * @param object patterns: Imported @freesewing/pattern-info */ -const testPatternDrafting = (design, Pattern, expect, models, patterns, log=false) => { +export const testPatternDrafting = (design, Pattern, expect, models, patterns, log=false) => { // Load non-human measurements const nonHuman = nonHumanMeasurements(models) @@ -145,4 +145,3 @@ const testPatternDrafting = (design, Pattern, expect, models, patterns, log=fals } } -module.exports = testPatternDrafting diff --git a/tests/patterns/non-human-measurements.js b/tests/patterns/non-human-measurements.mjs similarity index 96% rename from tests/patterns/non-human-measurements.js rename to tests/patterns/non-human-measurements.mjs index 76571a9a0a1..6fd61c46604 100644 --- a/tests/patterns/non-human-measurements.js +++ b/tests/patterns/non-human-measurements.mjs @@ -10,7 +10,7 @@ const nonHuman = { } const round = val => Math.round(val*10)/10 -module.exports = function nonHumanMeasurements(models) { +export const nonHumanMeasurements = models => { const { withBreasts, withoutBreasts } = models diff --git a/tests/patterns/sampling.js b/tests/patterns/sampling.mjs similarity index 94% rename from tests/patterns/sampling.js rename to tests/patterns/sampling.mjs index f25e36886dc..4fe2ddfc728 100644 --- a/tests/patterns/sampling.js +++ b/tests/patterns/sampling.mjs @@ -1,4 +1,4 @@ -const nonHumanMeasurements = require('./non-human-measurements.js') +import { nonHumanMeasurements } from './non-human-measurements.mjs' /* * This runs unit tests for pattern sampling * It expects the following: @@ -14,7 +14,7 @@ const nonHumanMeasurements = require('./non-human-measurements.js') // Some patterns are deprecated and won't support more stringent doll/giant tests const deprecated = ['theo'] -const testPatternSampling = (design, Pattern, expect, models, patterns) => { +export const testPatternSampling = (design, Pattern, expect, models, patterns) => { // Load non-human measurements const nonHuman = nonHumanMeasurements(models) @@ -112,4 +112,3 @@ const testPatternSampling = (design, Pattern, expect, models, patterns) => { } -module.exports = testPatternSampling diff --git a/tests/plugins/shared.mjs b/tests/plugins/shared.mjs new file mode 100644 index 00000000000..d5d2b5d6c11 --- /dev/null +++ b/tests/plugins/shared.mjs @@ -0,0 +1,42 @@ +import freesewing from '@freesewing/core' +import chai from 'chai' +/* + * This runs unit tests for the plugin configuration + * It expects the following: + * + * @param object plugin: The plugin object + * @param object freesewing: Imported @freesewing/core + * @param object expect: Imported chai.expect + */ +export const sharedPluginTests = plugin => { + + describe('Shared Plugin Tests', () => { + it('Should have a name property', () => { + chai.expect(typeof plugin.name).to.equal('string') + chai.expect(plugin.name.length).to.be.greaterThan(2) + }) + it('Should have a version property', () => { + chai.expect(typeof plugin.version).to.equal('string') + chai.expect(plugin.version.length).to.be.greaterThan(2) + }) + it('Version should be a proper semantic version', () => { + chai.expect(plugin.version.split('.').length).to.equal(3) + }) + + if ([ + // These don't set their version + '@freesewing/plugin-versionfree-svg', + '@freesewing/plugin-bundle', + ].indexOf(plugin.name) === -1) { + const pattern = new freesewing.Pattern().use(plugin) + pattern.draft().render() + const version = plugin.name.split('@').pop().split('/').join(':') + + it('Should set the plugin name:version attribute', () => { + chai.expect(pattern.svg.attributes.get(version)).to.equal(plugin.version) + }) + } + }) + +} +