summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-06-11 22:22:47 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-06-11 22:22:47 +0200
commitbe8d25968bfa511aa856759f6fbe9dfa5c8248f6 (patch)
tree650f99c6ce70bb8038883b6d7cff853ec0c48577
parentcb35325c16760721e55783c4624ee63daa973f7c (diff)
Added a test to ensure that importing with requirejs actually works
Re #10
-rw-r--r--.eslintrc.json4
-rw-r--r--package.json3
-rw-r--r--south-african-id-parser.js2
-rw-r--r--test/.eslintrc.json5
-rw-r--r--test/amd.js22
-rw-r--r--test/test.js3
6 files changed, 31 insertions, 8 deletions
diff --git a/.eslintrc.json b/.eslintrc.json
index 92c421c..b2af456 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,9 +1,5 @@
{
"env": {
- "browser": true,
- "commonjs": true,
- "es2021": true,
- "amd": true
},
"extends": "eslint:recommended",
"parserOptions": {
diff --git a/package.json b/package.json
index b66f554..1d5c33d 100644
--- a/package.json
+++ b/package.json
@@ -32,6 +32,7 @@
"chai": "^4.3.7",
"eslint": "^8.42.0",
"jsdoc": "^4.0.2",
- "mocha": "^10.2.0"
+ "mocha": "^10.2.0",
+ "requirejs": "^2.3.6"
}
}
diff --git a/south-african-id-parser.js b/south-african-id-parser.js
index 73450ea..62f5e15 100644
--- a/south-african-id-parser.js
+++ b/south-african-id-parser.js
@@ -1,6 +1,7 @@
(function (global, factory) {
'use strict';
+ /* eslint-disable no-undef */
if (typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
@@ -8,6 +9,7 @@
} else {
global.saIdParser = factory();
}
+ /* eslint-enable */
}(this, function () {
'use strict';
diff --git a/test/.eslintrc.json b/test/.eslintrc.json
new file mode 100644
index 0000000..10d2238
--- /dev/null
+++ b/test/.eslintrc.json
@@ -0,0 +1,5 @@
+{
+ "env": {
+ "node": true
+ }
+}
diff --git a/test/amd.js b/test/amd.js
new file mode 100644
index 0000000..03bd716
--- /dev/null
+++ b/test/amd.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var path = require('path');
+var mocha = require('mocha');
+var describe = mocha.describe;
+var it = mocha.it;
+var expect = require('chai').expect;
+const requirejs = require('requirejs');
+
+// node require isn't provided here, so it has to use the AMD import option to
+// import it.
+requirejs.config({
+ baseUrl: path.join(__dirname, "..")
+});
+
+describe('Asynchronous Module Definition', function () {
+ it('can import the module using RequireJS', function() {
+ var saIdParser = requirejs('south-african-id-parser.js');
+ var validIdNumber = '1012311412187';
+ expect(saIdParser.validate(validIdNumber)).to.equal(true);
+ });
+});
diff --git a/test/test.js b/test/test.js
index 7fdf6d7..c31f179 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,7 +1,4 @@
'use strict';
-/*jshint
- node: true
-*/
var mocha = require('mocha');
var describe = mocha.describe;