chore: Added shared tests and templates for plugins
This commit is contained in:
parent
028a6e4cce
commit
2d2db41621
12 changed files with 171 additions and 26 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: '!'
|
||||
|
|
|
@ -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(
|
10
config/templates/tests/plugins/shared.test.mjs.template
Normal file
10
config/templates/tests/plugins/shared.test.mjs.template
Normal 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)
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [12.x]
|
||||
node-version: [14.x]
|
||||
|
||||
{{=<% %>=}}
|
||||
steps:
|
||||
|
|
42
config/templates/workflows/tests.plugin.yml
Normal file
42
config/templates/workflows/tests.plugin.yml
Normal 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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
42
tests/plugins/shared.mjs
Normal file
42
tests/plugins/shared.mjs
Normal 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)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue