diff --git a/package-lock.json b/package-lock.json
index dcd7e46..d357d0e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,7 +9,6 @@
"license": "MIT",
"dependencies": {
"@jscad/openjscad": "github:mrzealot/oldjscad",
- "chai-as-promised": "^7.1.1",
"fs-extra": "^9.0.1",
"js-yaml": "^3.14.0",
"kle-serial": "github:mrzealot/kle-serial",
@@ -24,6 +23,8 @@
"@rollup/plugin-commonjs": "^13.0.2",
"@rollup/plugin-replace": "^2.3.3",
"chai": "^4.2.0",
+ "chai-as-promised": "^7.1.1",
+ "dir-compare": "^3.3.0",
"glob": "^7.1.6",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
@@ -833,6 +834,7 @@
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
+ "dev": true,
"engines": {
"node": "*"
}
@@ -932,6 +934,15 @@
"url": "https://opencollective.com/browserslist"
}
},
+ "node_modules/buffer-equal": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-1.0.0.tgz",
+ "integrity": "sha1-WWFrSYME1Var1GaWayLu2j7KX74=",
+ "dev": true,
+ "engines": {
+ "node": ">=0.4.0"
+ }
+ },
"node_modules/caching-transform": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz",
@@ -969,6 +980,7 @@
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz",
"integrity": "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==",
+ "dev": true,
"dependencies": {
"assertion-error": "^1.1.0",
"check-error": "^1.0.2",
@@ -985,6 +997,7 @@
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz",
"integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==",
+ "dev": true,
"dependencies": {
"check-error": "^1.0.2"
},
@@ -1024,6 +1037,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
+ "dev": true,
"engines": {
"node": "*"
}
@@ -1225,6 +1239,7 @@
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
+ "dev": true,
"dependencies": {
"type-detect": "^4.0.0"
},
@@ -1264,6 +1279,16 @@
"node": ">=0.3.1"
}
},
+ "node_modules/dir-compare": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/dir-compare/-/dir-compare-3.3.0.tgz",
+ "integrity": "sha512-J7/et3WlGUCxjdnD3HAAzQ6nsnc0WL6DD7WcwJb7c39iH1+AWfg+9OqzJNaI6PkBwBvm1mhZNL9iY/nRiZXlPg==",
+ "dev": true,
+ "dependencies": {
+ "buffer-equal": "^1.0.0",
+ "minimatch": "^3.0.4"
+ }
+ },
"node_modules/electron-to-chromium": {
"version": "1.3.778",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.778.tgz",
@@ -1493,6 +1518,7 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
+ "dev": true,
"engines": {
"node": "*"
}
@@ -2551,6 +2577,7 @@
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz",
"integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==",
+ "dev": true,
"engines": {
"node": "*"
}
@@ -2966,6 +2993,7 @@
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
+ "dev": true,
"engines": {
"node": ">=4"
}
@@ -3962,7 +3990,8 @@
"assertion-error": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
- "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw=="
+ "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
+ "dev": true
},
"astring": {
"version": "1.7.5",
@@ -4037,6 +4066,12 @@
"node-releases": "^1.1.71"
}
},
+ "buffer-equal": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-1.0.0.tgz",
+ "integrity": "sha1-WWFrSYME1Var1GaWayLu2j7KX74=",
+ "dev": true
+ },
"caching-transform": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz",
@@ -4064,6 +4099,7 @@
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz",
"integrity": "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==",
+ "dev": true,
"requires": {
"assertion-error": "^1.1.0",
"check-error": "^1.0.2",
@@ -4077,6 +4113,7 @@
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz",
"integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==",
+ "dev": true,
"requires": {
"check-error": "^1.0.2"
}
@@ -4105,7 +4142,8 @@
"check-error": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
- "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII="
+ "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
+ "dev": true
},
"chokidar": {
"version": "3.5.1",
@@ -4261,6 +4299,7 @@
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
+ "dev": true,
"requires": {
"type-detect": "^4.0.0"
}
@@ -4288,6 +4327,16 @@
"integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==",
"dev": true
},
+ "dir-compare": {
+ "version": "3.3.0",
+ "resolved": "https://registry.npmjs.org/dir-compare/-/dir-compare-3.3.0.tgz",
+ "integrity": "sha512-J7/et3WlGUCxjdnD3HAAzQ6nsnc0WL6DD7WcwJb7c39iH1+AWfg+9OqzJNaI6PkBwBvm1mhZNL9iY/nRiZXlPg==",
+ "dev": true,
+ "requires": {
+ "buffer-equal": "^1.0.0",
+ "minimatch": "^3.0.4"
+ }
+ },
"electron-to-chromium": {
"version": "1.3.778",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.778.tgz",
@@ -4439,7 +4488,8 @@
"get-func-name": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
- "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE="
+ "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
+ "dev": true
},
"get-package-type": {
"version": "0.1.0",
@@ -5244,7 +5294,8 @@
"pathval": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz",
- "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ=="
+ "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==",
+ "dev": true
},
"picomatch": {
"version": "2.3.0",
@@ -5551,7 +5602,8 @@
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
- "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="
+ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
+ "dev": true
},
"type-fest": {
"version": "0.8.1",
diff --git a/package.json b/package.json
index d51b6e7..cd38593 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,6 @@
},
"dependencies": {
"@jscad/openjscad": "github:mrzealot/oldjscad",
- "chai-as-promised": "^7.1.1",
"fs-extra": "^9.0.1",
"js-yaml": "^3.14.0",
"kle-serial": "github:mrzealot/kle-serial",
@@ -28,6 +27,8 @@
"@rollup/plugin-commonjs": "^13.0.2",
"@rollup/plugin-replace": "^2.3.3",
"chai": "^4.2.0",
+ "chai-as-promised": "^7.1.1",
+ "dir-compare": "^3.3.0",
"glob": "^7.1.6",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
diff --git a/test/cli/basic/command b/test/cli/basic/command
new file mode 100644
index 0000000..815a7bf
--- /dev/null
+++ b/test/cli/basic/command
@@ -0,0 +1 @@
+node src/cli.js test/fixtures/minimal.yaml
\ No newline at end of file
diff --git a/test/cli/basic/log b/test/cli/basic/log
new file mode 100644
index 0000000..7df27c1
--- /dev/null
+++ b/test/cli/basic/log
@@ -0,0 +1,13 @@
+Ergogen v2.0.0 CLI
+
+Interpreting format: YAML
+Preprocessing input...
+Calculating variables...
+Parsing points...
+Generating outlines...
+Extruding cases...
+Scaffolding PCBs...
+Output would be empty, rerunning in debug mode...
+Writing output to disk...
+Done.
+
diff --git a/test/cli/basic/reference/canonical.yaml b/test/cli/basic/reference/canonical.yaml
new file mode 100644
index 0000000..051236a
--- /dev/null
+++ b/test/cli/basic/reference/canonical.yaml
@@ -0,0 +1,7 @@
+points:
+ zones:
+ matrix:
+ columns:
+ col: {}
+ rows:
+ row: {}
diff --git a/test/cli/basic/reference/points/demo.dxf b/test/cli/basic/reference/points/demo.dxf
new file mode 100644
index 0000000..8082f61
--- /dev/null
+++ b/test/cli/basic/reference/points/demo.dxf
@@ -0,0 +1,98 @@
+0
+SECTION
+2
+HEADER
+9
+$INSUNITS
+70
+4
+0
+ENDSEC
+0
+SECTION
+2
+TABLES
+0
+TABLE
+2
+LTYPE
+0
+LTYPE
+72
+65
+70
+64
+2
+CONTINUOUS
+3
+______
+73
+0
+40
+0
+0
+ENDTAB
+0
+TABLE
+2
+LAYER
+0
+ENDTAB
+0
+ENDSEC
+0
+SECTION
+2
+ENTITIES
+0
+LINE
+8
+0
+10
+-9
+20
+9
+11
+9
+21
+9
+0
+LINE
+8
+0
+10
+9
+20
+9
+11
+9
+21
+-9
+0
+LINE
+8
+0
+10
+9
+20
+-9
+11
+-9
+21
+-9
+0
+LINE
+8
+0
+10
+-9
+20
+-9
+11
+-9
+21
+9
+0
+ENDSEC
+0
+EOF
\ No newline at end of file
diff --git a/test/cli/basic/reference/points/demo.json b/test/cli/basic/reference/points/demo.json
new file mode 100644
index 0000000..d400097
--- /dev/null
+++ b/test/cli/basic/reference/points/demo.json
@@ -0,0 +1,69 @@
+{
+ "models": {
+ "export": {
+ "models": {
+ "matrix_col_row": {
+ "paths": {
+ "top": {
+ "type": "line",
+ "origin": [
+ -9,
+ 9
+ ],
+ "end": [
+ 9,
+ 9
+ ]
+ },
+ "right": {
+ "type": "line",
+ "origin": [
+ 9,
+ 9
+ ],
+ "end": [
+ 9,
+ -9
+ ]
+ },
+ "bottom": {
+ "type": "line",
+ "origin": [
+ 9,
+ -9
+ ],
+ "end": [
+ -9,
+ -9
+ ]
+ },
+ "left": {
+ "type": "line",
+ "origin": [
+ -9,
+ -9
+ ],
+ "end": [
+ -9,
+ 9
+ ]
+ }
+ },
+ "origin": [
+ 0,
+ 0
+ ]
+ }
+ },
+ "origin": [
+ 0,
+ 0
+ ]
+ }
+ },
+ "units": "mm",
+ "origin": [
+ 0,
+ 0
+ ]
+}
diff --git a/test/cli/basic/reference/points/demo.svg b/test/cli/basic/reference/points/demo.svg
new file mode 100644
index 0000000..bcd7456
--- /dev/null
+++ b/test/cli/basic/reference/points/demo.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/test/cli/basic/reference/points/points.json b/test/cli/basic/reference/points/points.json
new file mode 100644
index 0000000..17e880a
--- /dev/null
+++ b/test/cli/basic/reference/points/points.json
@@ -0,0 +1,34 @@
+{
+ "matrix_col_row": {
+ "x": 0,
+ "y": 0,
+ "r": 0,
+ "meta": {
+ "shift": [
+ 0,
+ 0
+ ],
+ "rotate": 0,
+ "padding": 19,
+ "width": 1,
+ "height": 1,
+ "skip": false,
+ "asym": "both",
+ "name": "matrix_col_row",
+ "colrow": "col_row",
+ "col": {
+ "stagger": 0,
+ "spread": 0,
+ "rotate": 0,
+ "origin": [
+ 0,
+ 0
+ ],
+ "rows": {},
+ "key": {},
+ "name": "col"
+ },
+ "row": "row"
+ }
+ }
+}
diff --git a/test/cli/basic/reference/raw.txt b/test/cli/basic/reference/raw.txt
new file mode 100644
index 0000000..c878ca1
--- /dev/null
+++ b/test/cli/basic/reference/raw.txt
@@ -0,0 +1,3 @@
+points.zones.matrix:
+ columns.col: {}
+ rows.row: {}
\ No newline at end of file
diff --git a/test/cli/basic/reference/units.json b/test/cli/basic/reference/units.json
new file mode 100644
index 0000000..3d3777b
--- /dev/null
+++ b/test/cli/basic/reference/units.json
@@ -0,0 +1,5 @@
+{
+ "u": 19,
+ "cx": 18,
+ "cy": 17
+}
diff --git a/test/cli/missing_input/command b/test/cli/missing_input/command
new file mode 100644
index 0000000..d259550
--- /dev/null
+++ b/test/cli/missing_input/command
@@ -0,0 +1 @@
+node src/cli.js
diff --git a/test/cli/missing_input/error b/test/cli/missing_input/error
new file mode 100644
index 0000000..8948ed0
--- /dev/null
+++ b/test/cli/missing_input/error
@@ -0,0 +1 @@
+Usage: ergogen [options]
diff --git a/test/index.js b/test/index.js
index 3aa03f4..8d98290 100644
--- a/test/index.js
+++ b/test/index.js
@@ -32,6 +32,7 @@ const cap = s => s.charAt(0).toUpperCase() + s.slice(1)
const test = function(input_path) {
this.timeout(120000)
+ this.slow(120000)
title = path.basename(input_path, '.yaml').split('_').join(' ')
it(title, async function() {
const input = yaml.load(fs.readFileSync(input_path).toString())
@@ -100,3 +101,49 @@ if (what) {
})
}
}
+
+// End-to-end tests to actually drive the CLI as well
+// --what filter is 'cli'
+// --dump is meaningless (just use the CLI itself)
+
+const read = (d, p) => fs.readFileSync(path.join(d, p)).toString()
+const exists = (d, p) => fs.existsSync(path.join(d, p))
+const { execSync } = require('child_process')
+const dircompare = require('dir-compare')
+
+if (!what || what.includes('cli')) {
+ describe('CLI', function() {
+ this.timeout(120000)
+ this.slow(120000)
+ for (const t of glob.sync(path.join(__dirname, 'cli/*'))) {
+ it(cap(path.basename(t).split('_').join(' ')), function() {
+ const command = read(t, 'command')
+ const output_path = exists(t, 'path') ? read(t, 'path') : 'output'
+ const version_regex = /\bv\d+\.\d+\.\d+\b/
+ // correct execution
+ if (exists(t, 'log')) {
+ const ref_log = read(t, 'log').replace(version_regex, '')
+ const actual_log = execSync(command).toString().replace(version_regex, '')
+ actual_log.should.equal(ref_log)
+ const comp_res = dircompare.compareSync(output_path, path.join(t, 'reference'), {
+ compareContent: true
+ })
+ comp_res.same.should.be.true
+ fs.removeSync(output_path)
+ } else {
+ const ref_error = read(t, 'error').replace(version_regex, '')
+ try {
+ execSync(command, {stdio: 'pipe'})
+ throw 'should_have_thrown'
+ } catch (ex) {
+ if (ex === 'should_have_thrown') {
+ throw new Error('This command should have thrown!')
+ }
+ const actual_error = ex.stderr.toString().replace(version_regex, '')
+ actual_error.should.equal(ref_error)
+ }
+ }
+ })
+ }
+ })
+}
\ No newline at end of file
diff --git a/test/unit/interface.js b/test/unit/interface.js
index 4bdedf6..2cfb3e4 100644
--- a/test/unit/interface.js
+++ b/test/unit/interface.js
@@ -13,6 +13,9 @@ const kle = load('atreus_kle.json')
describe('Interface', function() {
+ this.timeout(120000)
+ this.slow(120000)
+
it('debug', async function() {
// to check whether the output has "private" exports
const underscore = obj => {