chore(plugin-measurements): Ported to v3
This commit is contained in:
parent
717a2732d6
commit
bd156862d4
5 changed files with 39 additions and 27 deletions
|
@ -14,7 +14,7 @@ const banner = `/**
|
|||
const options = {
|
||||
banner: { js: banner },
|
||||
bundle: true,
|
||||
entryPoints: ['src/index.js'],
|
||||
entryPoints: ['src/index.mjs'],
|
||||
format: 'esm',
|
||||
outfile: 'dist/index.mjs',
|
||||
external: ["@freesewing"],
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
|
||||
"lab": "cd ../../sites/lab && yarn start",
|
||||
"tips": "node ../../scripts/help.mjs",
|
||||
"prettier": "npx prettier --write 'src/*.js' 'tests/*.mjs'",
|
||||
"prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'",
|
||||
"testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
|
||||
"cibuild_step1": "node --experimental-json-modules build.mjs"
|
||||
},
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import pkg from '../package.json'
|
||||
import { name, version } from '../package.json'
|
||||
|
||||
export default {
|
||||
name: pkg.name,
|
||||
version: pkg.version,
|
||||
export const plugin = {
|
||||
name,
|
||||
version,
|
||||
hooks: {
|
||||
preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-measurements', pkg.version),
|
||||
preDraft: function ({ settings }) {
|
||||
if (settings.measurements) {
|
||||
if (
|
||||
|
@ -36,3 +35,8 @@ export default {
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
// More specifically named exports
|
||||
export const measurementsPlugin = plugin
|
||||
export const pluginMeasurements = plugin
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import chai from 'chai'
|
||||
import freesewing from '@freesewing/core'
|
||||
import plugin from '../dist/index.mjs'
|
||||
import { Design, Pattern } from '@freesewing/core'
|
||||
import { plugin } from './dist/index.mjs'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
|
@ -13,8 +13,8 @@ const measurements = {
|
|||
crossSeamFront: 42
|
||||
}
|
||||
|
||||
const pattern = new freesewing.Pattern().use(plugin)
|
||||
pattern.apply({ measurements }).draft().render()
|
||||
const pattern = new Pattern().use(plugin)
|
||||
pattern.apply({ measurements } ).draft()
|
||||
|
||||
describe('Measurements Plugin Tests', () => {
|
||||
it('Should set the extra measurements', () => {
|
||||
|
@ -27,20 +27,26 @@ describe('Measurements Plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('Should calculate seatFront from seat and seatBack', function () {
|
||||
let config = {measurements:{}}
|
||||
const testPattern = new freesewing.Design(config,plugin)
|
||||
let pattern = new testPattern()
|
||||
let userMeasurements = {seat: 50, seatBack: 20}
|
||||
const config = {measurements:{}}
|
||||
const testPattern = new Design({
|
||||
measurements: {},
|
||||
plugins: [plugin]
|
||||
})
|
||||
const pattern = new testPattern()
|
||||
const userMeasurements = {seat: 50, seatBack: 20}
|
||||
pattern.settings.measurements = userMeasurements
|
||||
pattern.draft()
|
||||
expect(pattern.settings.measurements.seatFront).to.equal(30)
|
||||
})
|
||||
|
||||
it('Should calculate waistFrontArc and waistBackArc from waist and waistBack', function () {
|
||||
let config = {measurements:{}}
|
||||
const testPattern = new freesewing.Design(config,plugin)
|
||||
let pattern = new testPattern()
|
||||
let userMeasurements = {waist: 50, waistBack: 20}
|
||||
const config = {measurements:{}}
|
||||
const testPattern = new Design({
|
||||
measurements: {},
|
||||
plugins: [plugin]
|
||||
})
|
||||
const pattern = new testPattern()
|
||||
const userMeasurements = {waist: 50, waistBack: 20}
|
||||
pattern.settings.measurements = userMeasurements
|
||||
pattern.draft()
|
||||
expect(pattern.settings.measurements.waistFrontArc).to.equal(15)
|
||||
|
@ -48,10 +54,13 @@ describe('Measurements Plugin Tests', () => {
|
|||
})
|
||||
|
||||
it('Should calculate crossSeamBack from crossSeam and crossSeamFront', function () {
|
||||
let config = {measurements:{}}
|
||||
const testPattern = new freesewing.Design(config,plugin)
|
||||
let pattern = new testPattern()
|
||||
let userMeasurements = {crossSeam: 50, crossSeamFront: 20}
|
||||
const config = {measurements:{}}
|
||||
const testPattern = new Design({
|
||||
measurements: {},
|
||||
plugins: [plugin]
|
||||
})
|
||||
const pattern = new testPattern()
|
||||
const userMeasurements = {crossSeam: 50, crossSeamFront: 20}
|
||||
pattern.settings.measurements = userMeasurements
|
||||
pattern.draft()
|
||||
expect(pattern.settings.measurements.crossSeamBack).to.equal(30)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// This file is auto-generated.
|
||||
// Changes you make will be overwritten.
|
||||
import plugin from './dist/index.mjs'
|
||||
// This file is auto-generated | Any changes you make will be overwritten.
|
||||
import { plugin } from './dist/index.mjs'
|
||||
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
|
||||
|
||||
|
||||
// Run shared tests
|
||||
sharedPluginTests(plugin)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue