make dist absolutePath browser-safe, add test
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
"test": "npm run lint-errors && npm run just-test-in-node",
|
"test": "npm run lint-errors && npm run just-test-in-node",
|
||||||
"test-in-node": "npm run lint-errors && npm run just-test-in-node",
|
"test-in-node": "npm run lint-errors && npm run just-test-in-node",
|
||||||
"just-test": "karma start --config karma.conf.js",
|
"just-test": "karma start --config karma.conf.js",
|
||||||
"just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components test/bugs"
|
"just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components test/bugs test/swagger-ui-dist-package"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-polyfill": "^6.23.0",
|
"babel-polyfill": "^6.23.0",
|
||||||
|
|||||||
14
swagger-ui-dist-package/absolute-path.js
Normal file
14
swagger-ui-dist-package/absolute-path.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* getAbsoluteFSPath
|
||||||
|
* @return {string} When run in NodeJS env, returns the absolute path to the current directory
|
||||||
|
* When run outside of NodeJS, will return an error message
|
||||||
|
*/
|
||||||
|
const getAbsoluteFSPath = () => {
|
||||||
|
// detect whether we are running in a browser or nodejs
|
||||||
|
if (typeof module !== "undefined" && module.exports) {
|
||||||
|
return require("path").resolve(__dirname)
|
||||||
|
}
|
||||||
|
return "Error! absolutePath only available when running in NodeJS"
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getAbsoluteFSPath()
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
const path = require('path')
|
module.exports.SwaggerUIBundle = require("./swagger-ui-bundle.js")
|
||||||
|
module.exports.SwaggerUIStandalonePreset = require("./swagger-ui-standalone-preset.js")
|
||||||
|
module.exports.absolutePath = require("./.absolute-path.js")
|
||||||
|
|
||||||
module.exports.SwaggerUIBundle = require('./swagger-ui-bundle.js')
|
|
||||||
module.exports.SwaggerUIStandalonePreset = require('./swagger-ui-standalone-preset.js')
|
|
||||||
|
|
||||||
module.exports.absolutePath = path.resolve(__dirname)
|
|
||||||
|
|||||||
13
test/swagger-ui-dist-package/absolute-path.js
Normal file
13
test/swagger-ui-dist-package/absolute-path.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
import expect from "expect"
|
||||||
|
import path from "path"
|
||||||
|
import absolutePath from "../../swagger-ui-dist-package/absolute-path"
|
||||||
|
|
||||||
|
describe("swagger-ui-dist", function(){
|
||||||
|
describe("absolutePath", function(){
|
||||||
|
it("has absolute path", function(){
|
||||||
|
const expectedPath = path.resolve(__dirname, "../../swagger-ui-dist-package")
|
||||||
|
expect(absolutePath).toEqual(expectedPath)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user