Skip to content

Commit

Permalink
chore: add test for loading via AMD
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed May 30, 2020
1 parent 2b058de commit d09056c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module.exports = function (config) {
frameworks: ['mocha', 'chai'],
files: [
'slug.js',
'test/**/*.js'
'node_modules/requirejs/require.js', // Used to test loading via AMD.
'test/**/*.js',
],
preprocessors: { 'slug.js': 'coverage' },
reporters: ['coverage'],
reporters: ['progress', 'coverage'],
coverageReporter: {
dir: '.nyc_output',
reporters: [
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"karma-mocha": "^2.0.1",
"mocha": "^7.0.0",
"nyc": "^15.0.1",
"requirejs": "^2.3.6",
"standard": "^14.3.3"
},
"licenses": [
Expand Down
21 changes: 20 additions & 1 deletion test/slug.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* global beforeEach, chai, describe, it */

const inBrowser = typeof window !== 'undefined'

describe('slug', function () {
const slug = (typeof window !== 'undefined' && window.slug) || require('../slug')
const slug = (inBrowser && window.slug) || require('../slug')
const assert = typeof chai === 'undefined' ? require('assert') : chai.assert

beforeEach(slug.reset)
Expand Down Expand Up @@ -959,4 +961,21 @@ describe('slug', function () {
it('should handle a lone high surrogate by itself', () => {
assert.strictEqual(slug(String.fromCodePoint(55296)), 'ia')
})

it('should be able to be loaded via amd', (done) => {
const modulePath = inBrowser ? 'base/slug' : '../slug'
const requirejs = (inBrowser && window.requirejs) || require('requirejs')

if (!inBrowser) {
requirejs.config({
nodeRequire: require
})
}

requirejs([modulePath], function (amdSlug) {
// Use toString() to compare source code.
assert.deepStrictEqual(amdSlug.toString(), slug.toString())
done()
})
})
})

0 comments on commit d09056c

Please sign in to comment.