Merge branch 'master' of github.com:freesewing/plugin-validate
This commit is contained in:
parent
0f6cfa62b9
commit
f04510feb4
6 changed files with 4041 additions and 384 deletions
10
packages/plugin-validate/.babelrc
Normal file
10
packages/plugin-validate/.babelrc
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"useBuiltIns": "entry"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
9
packages/plugin-validate/.travis.yml
Normal file
9
packages/plugin-validate/.travis.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- "node"
|
||||
install:
|
||||
- npm install
|
||||
- npm run build
|
||||
script:
|
||||
- npm run test
|
||||
- npm run coverage
|
|
@ -4,12 +4,30 @@
|
|||
<h4 align="center"><em> <a title="Go to freesewing.org" href="https://freesewing.org/">freesewing</a></em>
|
||||
<br><sup>a library for made-to-measure sewing patterns</sup>
|
||||
</h4>
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/freesewing/plugin-validate"><img src="https://badgen.net/travis/freesewing/plugin-validate/master" alt="Travis build"></a>
|
||||
<a href="https://www.npmjs.com/package/@freesewing/plugin-validate"><img src="https://badgen.net/npm/v/@freesewing/plugin-validate" alt="Version"></a>
|
||||
<a href="https://www.npmjs.com/package/@freesewing/plugin-validate"><img src="https://badgen.net/npm/license/@freesewing/plugin-validate" alt="License"></a>
|
||||
<a href="https://codecov.io/gh/freesewing/plugin-validate"><img src="https://badgen.net/codecov/c/github/freesewing/plugin-validate/master" alt="Code coverage"></a>
|
||||
<a href="https://deepscan.io/dashboard#view=project&pid=3286&bid=28006"><img src="https://deepscan.io/api/projects/3286/branches/28006/badge/grade.svg" alt="DeepScan grade"></a>
|
||||
<a href="https://gitter.im/freesewing/freesewing"><img src="https://badgen.net/badge/chat/on%20Gitter/cyan" alt="Chat on Gitter"></a>
|
||||
<a href="https://freesewing.org/patrons/join"><img src="https://badgen.net/badge/become/a%20Patron/FF5B77" alt="Become a Patron"></a>
|
||||
</p>
|
||||
|
||||
# plugin-validate
|
||||
|
||||
A freesewing plugin that checks whether all required measurements are set prior to drafting your pattern.
|
||||
A freesewing plugin that validates your pattern and input. It will check for:
|
||||
|
||||
If a measurement is missing, this will throw an exception, and tell you which measurement is missing.
|
||||
- Missing measurements that are required by the pattern
|
||||
- Missing X or Y coordinates in points
|
||||
- Points that aren't points or don't have proper attributes
|
||||
- Paths that don't do anything (no ops)
|
||||
- Paths that use points that aren't valid points
|
||||
- Text that will cause problems for translation
|
||||
|
||||
On any of these, this plugin will throw an error.
|
||||
As such, it's not meant to be used in production, but rather during pattern
|
||||
development, to spot issues in your code.
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -45,14 +63,6 @@ To install, run:
|
|||
npm install @freesewing/plugin-validate
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
To build this plugin, run:
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
|
||||
## License: MIT
|
||||
|
||||
See [the license file](https://github.com/freesewing/plugin-validate/blob/master/LICENSE)
|
||||
|
|
4164
packages/plugin-validate/package-lock.json
generated
4164
packages/plugin-validate/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@freesewing/plugin-validate",
|
||||
"version": "0.2.0",
|
||||
"version": "0.3.0",
|
||||
"description": "A freesewing plugin that checks whether all required measurements are set prior to drafting your pattern ",
|
||||
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
|
||||
"license": "MIT",
|
||||
|
@ -24,13 +24,15 @@
|
|||
"minor": "npm version minor -m ':bookmark: v%s' && npm run build",
|
||||
"major": "npm version major -m ':bookmark: v%s' && npm run build",
|
||||
"precommit": "npm run pretty && lint-staged",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test": "nyc mocha --require @babel/register tests/*.test.js",
|
||||
"report": "nyc report --reporter=html mocha --require @babel/register tests/*.test.js",
|
||||
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && ./node_modules/.bin/codecov",
|
||||
"clean": "rimraf dist",
|
||||
"pretty": "npx prettier --write \"src/*.js\"",
|
||||
"lint": "eslint --fix \"src/*.js\"",
|
||||
"browserbuild": "rollup -c rollup.js --file dist/browser.js --format iife --name freesewing.plugins.validate",
|
||||
"nodebuild": "rollup -c rollup.js --file dist/index.js --format cjs",
|
||||
"modulebuild": "rollup -c rollup.js --file dist/index.mjs --format es",
|
||||
"browserbuild": "rollup -c rollup.js --file dist/browser.js --format iife -m true --name freesewing.plugins.validate",
|
||||
"nodebuild": "rollup -c rollup.js --file dist/index.js --format cjs -m true",
|
||||
"modulebuild": "rollup -c rollup.js --file dist/index.mjs --format es -m true",
|
||||
"build": "npm run clean && npm run browserbuild && npm run nodebuild && npm run modulebuild"
|
||||
},
|
||||
"husky": {
|
||||
|
@ -45,16 +47,24 @@
|
|||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-eslint": "^8.2.6",
|
||||
"@babel/core": "^7.1.0",
|
||||
"@babel/preset-env": "^7.1.0",
|
||||
"@babel/register": "^7.0.0",
|
||||
"chai": "^4.1.2",
|
||||
"chai-string": "1.4.0",
|
||||
"codecov": "^3.1.0",
|
||||
"eslint": "^5.2.0",
|
||||
"eslint-config-prettier": "^2.9.0",
|
||||
"eslint-plugin-prettier": "^2.6.2",
|
||||
"freesewing": "^0.18.3",
|
||||
"husky": "^0.14.3",
|
||||
"lint-staged": "^7.2.0",
|
||||
"mocha": "^5.2.0",
|
||||
"nyc": "12.0.2",
|
||||
"prettier": "^1.13.7",
|
||||
"rimraf": "^2.6.2",
|
||||
"rollup-plugin-babel": "^3.0.7",
|
||||
"rollup": "^0.66.2",
|
||||
"rollup-plugin-babel": "^4.0.3",
|
||||
"rollup-plugin-filesize": "^4.0.1",
|
||||
"rollup-plugin-json": "^3.0.0",
|
||||
"rollup-plugin-node-resolve": "^3.3.0",
|
||||
|
|
186
packages/plugin-validate/tests/validate.test.js
Normal file
186
packages/plugin-validate/tests/validate.test.js
Normal file
|
@ -0,0 +1,186 @@
|
|||
import freesewing from "freesewing";
|
||||
import { version } from "../package.json";
|
||||
let expect = require("chai").expect;
|
||||
let plugin = require("../dist/index.js");
|
||||
|
||||
it("Should set the plugin name:version attribute", () => {
|
||||
let pattern = new freesewing.Pattern().with(plugin);
|
||||
pattern.render();
|
||||
expect(pattern.svg.attributes.get("freesewing:plugin-validate")).to.equal(
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("Should should throw a missing measurement error", () => {
|
||||
let pattern = new freesewing.Pattern({
|
||||
measurements: ["chestCircumference"]
|
||||
});
|
||||
// We need to add the draft method before loading the
|
||||
// plugin, or we'll overwrite the hook listener
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.settings.measurements = { test: 12 };
|
||||
let err = "Missing measurement: chestCircumference";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on an invalid X-coordinate", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.test = new pattern.Point("booo", 12);
|
||||
let err = "X-value of point pattern.parts.test.points.test is not a number";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on an invalid Y-coordinate", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.test = new pattern.Point(12, "moooo");
|
||||
let err = "Y-value of point pattern.parts.test.points.test is not a number";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on an invalid point object", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.test = "nope";
|
||||
let err = "Point pattern.parts.test.points.test is not an object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on an invalid point attributes object", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.test = new pattern.Point(12, 34);
|
||||
pattern.parts.test.points.test.attributes = "fubar";
|
||||
let err =
|
||||
"attributes property of point pattern.parts.test.points.test is not an object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on an invalid text type", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.test = new pattern.Point(12, 34).attr(
|
||||
"data-text",
|
||||
{}
|
||||
);
|
||||
let err =
|
||||
"point pattern.parts.test.points.test has text that is not a string nor a number";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should skip text validation", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.test = new pattern.Point(12, 34)
|
||||
.attr("data-text", {})
|
||||
.attr("data-validate-skip-text", true);
|
||||
expect(typeof pattern.draft()).to.equal("undefined");
|
||||
});
|
||||
|
||||
it("Should throw on possible translation issues", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.test = new pattern.Point(12, 34).attr(
|
||||
"data-text",
|
||||
"hi :)"
|
||||
);
|
||||
let err = "point pattern.parts.test.points.test has text containing spaces";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on an invalid path object", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.paths.test = "nope";
|
||||
let err = "Path pattern.parts.test.paths.test is not an object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on a path object with invalid ops", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.paths.test = new pattern.Path();
|
||||
pattern.parts.test.paths.test.ops = "nope";
|
||||
let err =
|
||||
"ops property of path pattern.parts.test.paths.test is not an object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on a path with less than two ops", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.paths.test = new pattern.Path();
|
||||
let err = "Path pattern.parts.test.paths.test does not do anything";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on a path with an invalid point", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.paths.test = new pattern.Path()
|
||||
.move(new pattern.Point(0, 0))
|
||||
.line("nope");
|
||||
let err = "Point pattern.parts.test.points._unknown_ is not an object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on a path with an invalid attributes object", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(12, 34);
|
||||
pattern.parts.test.points.to = new pattern.Point(56, 78);
|
||||
pattern.parts.test.paths.test = new pattern.Path()
|
||||
.move(pattern.parts.test.points.from)
|
||||
.line(pattern.parts.test.points.to);
|
||||
pattern.parts.test.paths.test.attributes = "nope";
|
||||
let err =
|
||||
"attributes property of path pattern.parts.test.paths.test is not an object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw on an invalid snippet", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.points.from = new pattern.Point(12, 34);
|
||||
pattern.parts.test.snippets.test = "nope";
|
||||
let err = "pattern.parts.test.snippets.test is not a valid Snippet object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
||||
|
||||
it("Should throw for an snippet anchored on an invalid point", () => {
|
||||
let pattern = new freesewing.Pattern();
|
||||
pattern.draft = function() {};
|
||||
pattern.with(plugin);
|
||||
pattern.parts.test = new pattern.Part();
|
||||
pattern.parts.test.snippets.test = new pattern.Snippet("notch", "nope");
|
||||
let err = "Point pattern.parts.test.points._unknown_ is not an object";
|
||||
expect(() => pattern.draft()).to.throw(err);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue