chore(plugin-grainline): Added (esm) unit tests. See #408
This commit is contained in:
parent
03db76f82c
commit
b782e9d526
6 changed files with 58 additions and 44 deletions
|
@ -1,6 +1,12 @@
|
|||
# Change log for: @freesewing/plugin-grainline
|
||||
|
||||
|
||||
## unreleased (NaN-NaN-NaN)
|
||||
|
||||
### Added
|
||||
|
||||
- Added (esm) unit tests
|
||||
|
||||
## 2.0.0 (2019-08-25)
|
||||
|
||||
### Added
|
||||
|
|
|
@ -30,18 +30,23 @@
|
|||
"clean": "rimraf dist",
|
||||
"build": "rollup -c",
|
||||
"lernabuild": "rollup -c",
|
||||
"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",
|
||||
"pubtest": "npm publish --registry http://localhost:6662",
|
||||
"pubforce": "npm publish",
|
||||
"symlink": "mkdir -p ./node_modules/@freesewing && cd ./node_modules/@freesewing && ln -s -f ../../../* . && cd -",
|
||||
"start": "rollup -c -w",
|
||||
"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'"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@freesewing/core": "^2.19.5"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"devDependencies": {
|
||||
"mocha": "^9.1.1",
|
||||
"chai": "^4.2.0",
|
||||
"@babel/register": "^7.10.5"
|
||||
},
|
||||
"files": [
|
||||
"dist/*",
|
||||
"README.md",
|
||||
|
|
|
@ -5,7 +5,7 @@ export default {
|
|||
name: name,
|
||||
version: version,
|
||||
hooks: {
|
||||
preRender: svg => {
|
||||
preRender: (svg) => {
|
||||
if (svg.attributes.get('freesewing:plugin-grainline') === false) {
|
||||
svg.attributes.set('freesewing:plugin-grainline', version)
|
||||
svg.defs += markers
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
import freesewing from '@freesewing/core'
|
||||
import { version } from "../package.json";
|
||||
|
||||
|
||||
const expect = require("chai").expect;
|
||||
const plugin = require("../dist/index.js");
|
||||
const round = freesewing.utils.round
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
const pattern = new freesewing.Pattern().use(plugin);
|
||||
pattern.draft().render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-grainline")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should run the default grainline macro", () => {
|
||||
const pattern = new freesewing.Pattern().use(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20);
|
||||
pattern.parts.test.points.to = new pattern.Point(10, 230);
|
||||
const { macro } = pattern.parts.test.shorthand();
|
||||
macro("grainline", {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to
|
||||
});
|
||||
|
||||
const c = pattern.parts.test.paths.grainline;
|
||||
expect(c.attributes.get("class")).to.equal("note");
|
||||
expect(c.attributes.get("marker-start")).to.equal("url(#grainlineFrom)");
|
||||
expect(c.attributes.get("marker-end")).to.equal("url(#grainlineTo)");
|
||||
expect(c.attributes.get("data-text")).to.equal("grainline");
|
||||
expect(c.attributes.get("data-text-class")).to.equal("center fill-note");
|
||||
expect(c.ops[0].type).to.equal("move");
|
||||
expect(c.ops[1].type).to.equal("line");
|
||||
expect(round(c.ops[0].to.x)).to.equal(10);
|
||||
expect(round(c.ops[0].to.y)).to.equal(30.5);
|
||||
expect(round(c.ops[1].to.x)).to.equal(10);
|
||||
expect(round(c.ops[1].to.y)).to.equal(219.5);
|
||||
});
|
33
packages/plugin-grainline/tests/plugin.test.mjs
Normal file
33
packages/plugin-grainline/tests/plugin.test.mjs
Normal file
|
@ -0,0 +1,33 @@
|
|||
import chai from 'chai'
|
||||
import freesewing from '@freesewing/core'
|
||||
import plugin from '../dist/index.mjs'
|
||||
|
||||
const expect = chai.expect
|
||||
const round = freesewing.utils.round
|
||||
|
||||
describe('Grainline Plugin Tests', () => {
|
||||
it('Should run the default grainline macro', () => {
|
||||
const pattern = new freesewing.Pattern().use(plugin)
|
||||
pattern.parts.test = new pattern.Part()
|
||||
pattern.parts.test.points.from = new pattern.Point(10, 20)
|
||||
pattern.parts.test.points.to = new pattern.Point(10, 230)
|
||||
const { macro } = pattern.parts.test.shorthand()
|
||||
macro('grainline', {
|
||||
from: pattern.parts.test.points.from,
|
||||
to: pattern.parts.test.points.to,
|
||||
})
|
||||
|
||||
const c = pattern.parts.test.paths.grainline
|
||||
expect(c.attributes.get('class')).to.equal('note')
|
||||
expect(c.attributes.get('marker-start')).to.equal('url(#grainlineFrom)')
|
||||
expect(c.attributes.get('marker-end')).to.equal('url(#grainlineTo)')
|
||||
expect(c.attributes.get('data-text')).to.equal('grainline')
|
||||
expect(c.attributes.get('data-text-class')).to.equal('center fill-note')
|
||||
expect(c.ops[0].type).to.equal('move')
|
||||
expect(c.ops[1].type).to.equal('line')
|
||||
expect(round(c.ops[0].to.x)).to.equal(10)
|
||||
expect(round(c.ops[0].to.y)).to.equal(30.5)
|
||||
expect(round(c.ops[1].to.x)).to.equal(10)
|
||||
expect(round(c.ops[1].to.y)).to.equal(219.5)
|
||||
})
|
||||
})
|
10
packages/plugin-grainline/tests/shared.test.mjs
Normal file
10
packages/plugin-grainline/tests/shared.test.mjs
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)
|
Loading…
Add table
Add a link
Reference in a new issue