1
0
Fork 0

chore: Added shared tests and templates for plugins

This commit is contained in:
Joost De Cock 2021-11-27 16:54:50 +01:00
parent 028a6e4cce
commit 2d2db41621
12 changed files with 171 additions and 26 deletions

View file

@ -3,6 +3,54 @@ unreleased:
Added: Added:
core: core:
- Added the new attributes.setIfUnset() method - 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: Fixed:
plugin-buttons: plugin-buttons:

View file

@ -29,13 +29,16 @@ _types:
'axios': &axios '0.21.2' 'axios': &axios '0.21.2'
'react-intl': &react-intl '^5.17.6' 'react-intl': &react-intl '^5.17.6'
'prop-types': '^15.7.2' 'prop-types': '^15.7.2'
'mocha': '^9.1.1' 'mocha': &mocha '^9.1.1'
'chai': '^4.2.0' 'chai': &chai '^4.2.0'
'chai-string': '^1.5.0' '@babel/register': &babelregister '^7.10.5'
'@babel/register': '^7.10.5'
plugin: plugin:
peer: peer:
'@freesewing/core': *freesewing '@freesewing/core': *freesewing
dev:
'mocha': *mocha
'chai': *chai
'@babel/register': *babelregister
aaron: aaron:
peer: peer:
'@freesewing/brian': *freesewing '@freesewing/brian': *freesewing

View file

@ -10,11 +10,12 @@ _:
_types: _types:
pattern: pattern:
netlify: 'echo "Not configured yet"' netlify: 'echo "Not configured yet"'
test: '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.js --require @babel/register' testci: 'BABEL_ENV=production ./node_modules/.bin/_mocha tests/*.test.mjs --require @babel/register'
plugin: plugin:
test: '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'
prettier: "npx prettier --write 'src/*.js' 'tests/*.js'" 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: create-freesewing-pattern:
clean: '!' clean: '!'
nodebuild: '!' nodebuild: '!'

View file

@ -1,15 +1,17 @@
// This file is auto-generated. // This file is auto-generated.
// Changes you make will be overwritten. // Changes you make will be overwritten.
const expect = require("chai").expect; import chai from 'chai'
const models = require("@freesewing/models") import models from '@freesewing/models'
const patterns = require("@freesewing/pattern-info") import patterns from '@freesewing/pattern-info'
import {{ Pattern }} from '../dist/index.mjs'
const {{ Pattern }} = require('../dist')
// Shared tests // Shared tests
const testPatternConfig = require('../../../tests/patterns/config') import { testPatternConfig } from '../../../tests/patterns/config.mjs'
const testPatternDrafting = require('../../../tests/patterns/drafting') import { testPatternDrafting } from '../../../tests/patterns/drafting.mjs'
const testPatternSampling = require('../../../tests/patterns/sampling') import { testPatternSampling } from '../../../tests/patterns/sampling.mjs'
const expect = chai.expect
// Test config // Test config
testPatternConfig( testPatternConfig(

View file

@ -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)

View file

@ -17,7 +17,7 @@ jobs:
strategy: strategy:
matrix: matrix:
node-version: [12.x] node-version: [14.x]
{{=<% %>=}} {{=<% %>=}}
steps: steps:

View file

@ -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

View file

@ -20,7 +20,7 @@ const deprecated = ['theo']
* @param object models: Imported @freesewing/models * @param object models: Imported @freesewing/models
* @param object patterns: Imported @freesewing/pattern-info * @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('Metadata:', () => true)
it(` - 'name' should match package name`, () => { it(` - 'name' should match package name`, () => {
expect(pattern.config.name).to.equal(design) expect(pattern.config.name).to.equal(design)
@ -199,4 +199,3 @@ const testPatternConfig = (design, pattern, expect, models, patterns) => {
} }
} }
module.exports = testPatternConfig

View file

@ -1,4 +1,4 @@
const nonHumanMeasurements = require('./non-human-measurements.js') import { nonHumanMeasurements } from './non-human-measurements.mjs'
// Some patterns are different // Some patterns are different
const isGarment = design => ([ const isGarment = design => ([
@ -22,7 +22,7 @@ const deprecated = ['theo']
* @param object models: Imported @freesewing/models * @param object models: Imported @freesewing/models
* @param object patterns: Imported @freesewing/pattern-info * @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 // Load non-human measurements
const nonHuman = nonHumanMeasurements(models) const nonHuman = nonHumanMeasurements(models)
@ -145,4 +145,3 @@ const testPatternDrafting = (design, Pattern, expect, models, patterns, log=fals
} }
} }
module.exports = testPatternDrafting

View file

@ -10,7 +10,7 @@ const nonHuman = {
} }
const round = val => Math.round(val*10)/10 const round = val => Math.round(val*10)/10
module.exports = function nonHumanMeasurements(models) { export const nonHumanMeasurements = models => {
const { withBreasts, withoutBreasts } = models const { withBreasts, withoutBreasts } = models

View file

@ -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 * This runs unit tests for pattern sampling
* It expects the following: * 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 // Some patterns are deprecated and won't support more stringent doll/giant tests
const deprecated = ['theo'] const deprecated = ['theo']
const testPatternSampling = (design, Pattern, expect, models, patterns) => { export const testPatternSampling = (design, Pattern, expect, models, patterns) => {
// Load non-human measurements // Load non-human measurements
const nonHuman = nonHumanMeasurements(models) const nonHuman = nonHumanMeasurements(models)
@ -112,4 +112,3 @@ const testPatternSampling = (design, Pattern, expect, models, patterns) => {
} }
module.exports = testPatternSampling

42
tests/plugins/shared.mjs Normal file
View file

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