chore(core): Port tests to ESM
This commit is contained in:
parent
8af23b9b94
commit
547d11569d
14 changed files with 77 additions and 48 deletions
|
@ -4,7 +4,9 @@ import Point from './point'
|
||||||
import Path from './path'
|
import Path from './path'
|
||||||
import Snippet from './snippet'
|
import Snippet from './snippet'
|
||||||
import * as utils from './utils'
|
import * as utils from './utils'
|
||||||
import { version } from '../package.json'
|
import pkg from '../package.json' assert { type: 'json' }
|
||||||
|
|
||||||
|
const { version } = pkg
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Named exports will become the default in FreeSewing v3
|
* Named exports will become the default in FreeSewing v3
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
const expect = require("chai").expect;
|
import chai from "chai"
|
||||||
const Point = require("../dist/index.js").Point;
|
import { Point } from "./dist/index.mjs"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
const newAttr = () => new Point(0, 0).attributes;
|
const newAttr = () => new Point(0, 0).attributes;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
let expect = require("chai").expect;
|
import chai from "chai"
|
||||||
let freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
it("Design constructor should return pattern constructor", () => {
|
it("Design constructor should return pattern constructor", () => {
|
||||||
let design = new freesewing.Design({
|
let design = new freesewing.Design({
|
|
@ -1,4 +1,6 @@
|
||||||
var version = require('../../package.json').version
|
import pkg from '../../package.json' assert { type: 'json' }
|
||||||
|
|
||||||
|
const { version } = pkg
|
||||||
|
|
||||||
var render = {
|
var render = {
|
||||||
boilerplate: `<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg
|
boilerplate: `<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg
|
||||||
|
@ -363,4 +365,4 @@ var render = {
|
||||||
</svg>`
|
</svg>`
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = render
|
export default render
|
|
@ -1,8 +1,10 @@
|
||||||
let expect = require("chai").expect;
|
import chai from "chai"
|
||||||
let freesewing = require("../dist/index.js");
|
import { Pattern } from "./dist/index.mjs"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
it("Should contain all hooks", () => {
|
it("Should contain all hooks", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new Pattern();
|
||||||
let h = pattern.hooks;
|
let h = pattern.hooks;
|
||||||
let test = {
|
let test = {
|
||||||
preDraft: [],
|
preDraft: [],
|
|
@ -1,5 +1,7 @@
|
||||||
let expect = require("chai").expect;
|
import chai from "chai"
|
||||||
let freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Part', () => {
|
describe('Part', () => {
|
||||||
it("Svg constructor should initialize object", () => {
|
it("Svg constructor should initialize object", () => {
|
||||||
|
@ -122,7 +124,7 @@ it("Should raise a warning when setting a non-Point value in points", () => {
|
||||||
const part = new pattern.Part();
|
const part = new pattern.Part();
|
||||||
const { points } = part.shorthand()
|
const { points } = part.shorthand()
|
||||||
points.a = 'banana'
|
points.a = 'banana'
|
||||||
expect(pattern.events.warning.length).to.equal(3)
|
expect(pattern.events.warning.length).to.equal(4)
|
||||||
expect(pattern.events.warning[0]).to.equal('`points.a` was set with a value that is not a `Point` object')
|
expect(pattern.events.warning[0]).to.equal('`points.a` was set with a value that is not a `Point` object')
|
||||||
expect(pattern.events.warning[1]).to.equal('`points.a` was set with a `x` parameter that is not a `number`')
|
expect(pattern.events.warning[1]).to.equal('`points.a` was set with a `x` parameter that is not a `number`')
|
||||||
expect(pattern.events.warning[2]).to.equal('`points.a` was set with a `y` parameter that is not a `number`')
|
expect(pattern.events.warning[2]).to.equal('`points.a` was set with a `y` parameter that is not a `number`')
|
||||||
|
@ -134,7 +136,7 @@ it("Should raise a warning when setting a non-Snippet value in snippets", () =>
|
||||||
const part = new pattern.Part();
|
const part = new pattern.Part();
|
||||||
const { snippets } = part.shorthand()
|
const { snippets } = part.shorthand()
|
||||||
snippets.a = 'banana'
|
snippets.a = 'banana'
|
||||||
expect(pattern.events.warning.length).to.equal(3)
|
expect(pattern.events.warning.length).to.equal(4)
|
||||||
expect(pattern.events.warning[0]).to.equal('`snippets.a` was set with a value that is not a `Snippet` object')
|
expect(pattern.events.warning[0]).to.equal('`snippets.a` was set with a value that is not a `Snippet` object')
|
||||||
expect(pattern.events.warning[1]).to.equal('`snippets.a` was set with a `def` parameter that is not a `string`')
|
expect(pattern.events.warning[1]).to.equal('`snippets.a` was set with a `def` parameter that is not a `string`')
|
||||||
expect(pattern.events.warning[2]).to.equal('`snippets.a` was set with an `anchor` parameter that is not a `Point`')
|
expect(pattern.events.warning[2]).to.equal('`snippets.a` was set with an `anchor` parameter that is not a `Point`')
|
|
@ -1,6 +1,8 @@
|
||||||
const expect = require("chai").expect;
|
import chai from "chai"
|
||||||
const freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
const round = freesewing.utils.round;
|
|
||||||
|
const expect = chai.expect
|
||||||
|
const round = freesewing.utils.round
|
||||||
|
|
||||||
it("Should offset a line", () => {
|
it("Should offset a line", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new freesewing.Pattern();
|
|
@ -1,5 +1,7 @@
|
||||||
let expect = require("chai").expect;
|
import chai from "chai"
|
||||||
let freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
it("Pattern constructor should initialize object", () => {
|
it("Pattern constructor should initialize object", () => {
|
||||||
let pattern = new freesewing.Pattern({
|
let pattern = new freesewing.Pattern({
|
|
@ -1,7 +1,9 @@
|
||||||
const expect = require("chai").expect;
|
import chai from "chai"
|
||||||
const freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
const Point = freesewing.Point;
|
|
||||||
const round = freesewing.utils.round;
|
const expect = chai.expect
|
||||||
|
const Point = freesewing.Point
|
||||||
|
const round = freesewing.utils.round
|
||||||
|
|
||||||
it("Should return point object", () => {
|
it("Should return point object", () => {
|
||||||
let result = new Point(2, 4);
|
let result = new Point(2, 4);
|
|
@ -1,5 +1,7 @@
|
||||||
const expect = require("chai").expect;
|
import chai from "chai"
|
||||||
const freesewing = require("../dist/index.js");
|
import freesewing from "../dist/index.js"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
const measurements = { head: 400 }
|
const measurements = { head: 400 }
|
||||||
const toAbs = (val, { measurements }) => measurements.head * val
|
const toAbs = (val, { measurements }) => measurements.head * val
|
|
@ -1,5 +1,7 @@
|
||||||
let expect = require("chai").expect;
|
import chai from "chai"
|
||||||
let freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
it("Should create a snippet", () => {
|
it("Should create a snippet", () => {
|
||||||
let snip1 = new freesewing.Snippet("test", new freesewing.Point(12, 34));
|
let snip1 = new freesewing.Snippet("test", new freesewing.Point(12, 34));
|
|
@ -1,5 +1,7 @@
|
||||||
let expect = require("chai").expect;
|
import chai from "chai"
|
||||||
let freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new freesewing.Pattern();
|
||||||
let store = pattern.store;
|
let store = pattern.store;
|
|
@ -1,10 +1,13 @@
|
||||||
const version = require("../package.json").version;
|
import chai from "chai"
|
||||||
const render = require("./fixtures/render.js");
|
import chaiString from "chai-string"
|
||||||
const expect = require("chai").expect;
|
import freesewing from "./dist/index.mjs"
|
||||||
const chai = require("chai");
|
import pkg from '../package.json' assert { type: 'json' }
|
||||||
chai.use(require("chai-string"));
|
import render from "./fixtures/render.mjs"
|
||||||
const freesewing = require("../dist/index.js");
|
|
||||||
const round = freesewing.utils.round;
|
chai.use(chaiString)
|
||||||
|
const expect = chai.expect
|
||||||
|
const { version } = pkg
|
||||||
|
const round = freesewing.utils.round
|
||||||
|
|
||||||
it("Svg constructor should initialize object", () => {
|
it("Svg constructor should initialize object", () => {
|
||||||
let pattern = new freesewing.Pattern();
|
let pattern = new freesewing.Pattern();
|
|
@ -1,7 +1,9 @@
|
||||||
const expect = require("chai").expect;
|
import chai from "chai"
|
||||||
const freesewing = require("../dist/index.js");
|
import freesewing from "./dist/index.mjs"
|
||||||
const utils = freesewing.utils;
|
|
||||||
const round = utils.round;
|
const { expect } = chai
|
||||||
|
const utils = freesewing.utils
|
||||||
|
const round = utils.round
|
||||||
|
|
||||||
it("Should return the correct macro name", () => {
|
it("Should return the correct macro name", () => {
|
||||||
expect(utils.macroName("test")).to.equal("_macro_test");
|
expect(utils.macroName("test")).to.equal("_macro_test");
|
||||||
|
@ -377,8 +379,8 @@ it("Should not find intersections of this line and circle", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should find intersections between circles", () => {
|
it("Should find intersections between circles", () => {
|
||||||
A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
let A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
||||||
B = new freesewing.Point(30, 30).attr("data-circle", 35);
|
let B = new freesewing.Point(30, 30).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections1 = freesewing.utils.circlesIntersect(
|
let intersections1 = freesewing.utils.circlesIntersect(
|
||||||
A,
|
A,
|
||||||
|
@ -406,8 +408,8 @@ it("Should find intersections between circles", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections between non-overlapping circles", () => {
|
it("Should not find intersections between non-overlapping circles", () => {
|
||||||
A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
let A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
||||||
B = new freesewing.Point(90, 90).attr("data-circle", 35);
|
let B = new freesewing.Point(90, 90).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections = freesewing.utils.circlesIntersect(
|
let intersections = freesewing.utils.circlesIntersect(
|
||||||
A,
|
A,
|
||||||
|
@ -419,8 +421,8 @@ it("Should not find intersections between non-overlapping circles", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections between contained circles", () => {
|
it("Should not find intersections between contained circles", () => {
|
||||||
A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
let A = new freesewing.Point(10, 10).attr("data-circle", 15);
|
||||||
B = new freesewing.Point(10, 10).attr("data-circle", 35);
|
let B = new freesewing.Point(10, 10).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections = freesewing.utils.circlesIntersect(
|
let intersections = freesewing.utils.circlesIntersect(
|
||||||
A,
|
A,
|
||||||
|
@ -432,8 +434,8 @@ it("Should not find intersections between contained circles", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not find intersections between identical circles", () => {
|
it("Should not find intersections between identical circles", () => {
|
||||||
A = new freesewing.Point(10, 10).attr("data-circle", 35);
|
let A = new freesewing.Point(10, 10).attr("data-circle", 35);
|
||||||
B = new freesewing.Point(10, 10).attr("data-circle", 35);
|
let B = new freesewing.Point(10, 10).attr("data-circle", 35);
|
||||||
|
|
||||||
let intersections = freesewing.utils.circlesIntersect(
|
let intersections = freesewing.utils.circlesIntersect(
|
||||||
A,
|
A,
|
Loading…
Add table
Add a link
Reference in a new issue