From be8d25968bfa511aa856759f6fbe9dfa5c8248f6 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Sun, 11 Jun 2023 22:22:47 +0200 Subject: Added a test to ensure that importing with requirejs actually works Re #10 --- .eslintrc.json | 4 ---- package.json | 3 ++- south-african-id-parser.js | 2 ++ test/.eslintrc.json | 5 +++++ test/amd.js | 22 ++++++++++++++++++++++ test/test.js | 3 --- 6 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 test/.eslintrc.json create mode 100644 test/amd.js 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; -- cgit v1.2.3