1
0
Fork 0

chore(plugin-measurements): Ported to v3

This commit is contained in:
Joost De Cock 2022-08-28 13:25:12 +02:00
parent 717a2732d6
commit bd156862d4
5 changed files with 39 additions and 27 deletions

View file

@ -14,7 +14,7 @@ const banner = `/**
const options = { const options = {
banner: { js: banner }, banner: { js: banner },
bundle: true, bundle: true,
entryPoints: ['src/index.js'], entryPoints: ['src/index.mjs'],
format: 'esm', format: 'esm',
outfile: 'dist/index.mjs', outfile: 'dist/index.mjs',
external: ["@freesewing"], external: ["@freesewing"],

View file

@ -38,7 +38,7 @@
"vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs", "vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs",
"lab": "cd ../../sites/lab && yarn start", "lab": "cd ../../sites/lab && yarn start",
"tips": "node ../../scripts/help.mjs", "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", "testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js",
"cibuild_step1": "node --experimental-json-modules build.mjs" "cibuild_step1": "node --experimental-json-modules build.mjs"
}, },

View file

@ -1,10 +1,9 @@
import pkg from '../package.json' import { name, version } from '../package.json'
export default { export const plugin = {
name: pkg.name, name,
version: pkg.version, version,
hooks: { hooks: {
preRender: (svg) => svg.attributes.setIfUnset('freesewing:plugin-measurements', pkg.version),
preDraft: function ({ settings }) { preDraft: function ({ settings }) {
if (settings.measurements) { if (settings.measurements) {
if ( if (
@ -36,3 +35,8 @@ export default {
}, },
}, },
} }
// More specifically named exports
export const measurementsPlugin = plugin
export const pluginMeasurements = plugin

View file

@ -1,6 +1,6 @@
import chai from 'chai' import chai from 'chai'
import freesewing from '@freesewing/core' import { Design, Pattern } from '@freesewing/core'
import plugin from '../dist/index.mjs' import { plugin } from './dist/index.mjs'
const expect = chai.expect const expect = chai.expect
@ -13,8 +13,8 @@ const measurements = {
crossSeamFront: 42 crossSeamFront: 42
} }
const pattern = new freesewing.Pattern().use(plugin) const pattern = new Pattern().use(plugin)
pattern.apply({ measurements }).draft().render() pattern.apply({ measurements } ).draft()
describe('Measurements Plugin Tests', () => { describe('Measurements Plugin Tests', () => {
it('Should set the extra measurements', () => { it('Should set the extra measurements', () => {
@ -27,20 +27,26 @@ describe('Measurements Plugin Tests', () => {
}) })
it('Should calculate seatFront from seat and seatBack', function () { it('Should calculate seatFront from seat and seatBack', function () {
let config = {measurements:{}} const config = {measurements:{}}
const testPattern = new freesewing.Design(config,plugin) const testPattern = new Design({
let pattern = new testPattern() measurements: {},
let userMeasurements = {seat: 50, seatBack: 20} plugins: [plugin]
})
const pattern = new testPattern()
const userMeasurements = {seat: 50, seatBack: 20}
pattern.settings.measurements = userMeasurements pattern.settings.measurements = userMeasurements
pattern.draft() pattern.draft()
expect(pattern.settings.measurements.seatFront).to.equal(30) expect(pattern.settings.measurements.seatFront).to.equal(30)
}) })
it('Should calculate waistFrontArc and waistBackArc from waist and waistBack', function () { it('Should calculate waistFrontArc and waistBackArc from waist and waistBack', function () {
let config = {measurements:{}} const config = {measurements:{}}
const testPattern = new freesewing.Design(config,plugin) const testPattern = new Design({
let pattern = new testPattern() measurements: {},
let userMeasurements = {waist: 50, waistBack: 20} plugins: [plugin]
})
const pattern = new testPattern()
const userMeasurements = {waist: 50, waistBack: 20}
pattern.settings.measurements = userMeasurements pattern.settings.measurements = userMeasurements
pattern.draft() pattern.draft()
expect(pattern.settings.measurements.waistFrontArc).to.equal(15) 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 () { it('Should calculate crossSeamBack from crossSeam and crossSeamFront', function () {
let config = {measurements:{}} const config = {measurements:{}}
const testPattern = new freesewing.Design(config,plugin) const testPattern = new Design({
let pattern = new testPattern() measurements: {},
let userMeasurements = {crossSeam: 50, crossSeamFront: 20} plugins: [plugin]
})
const pattern = new testPattern()
const userMeasurements = {crossSeam: 50, crossSeamFront: 20}
pattern.settings.measurements = userMeasurements pattern.settings.measurements = userMeasurements
pattern.draft() pattern.draft()
expect(pattern.settings.measurements.crossSeamBack).to.equal(30) expect(pattern.settings.measurements.crossSeamBack).to.equal(30)

View file

@ -1,8 +1,7 @@
// This file is auto-generated. // This file is auto-generated | Any changes you make will be overwritten.
// Changes you make will be overwritten. import { plugin } from './dist/index.mjs'
import plugin from './dist/index.mjs'
import { sharedPluginTests } from '../../../tests/plugins/shared.mjs' import { sharedPluginTests } from '../../../tests/plugins/shared.mjs'
// Run shared tests // Run shared tests
sharedPluginTests(plugin) sharedPluginTests(plugin)