Browse Source

make dist absolutePath browser-safe, add test

bubble
Dylan 7 years ago
parent
commit
df149c543b
4 changed files with 31 additions and 6 deletions
  1. +1
    -1
      package.json
  2. +14
    -0
      swagger-ui-dist-package/absolute-path.js
  3. +3
    -5
      swagger-ui-dist-package/index.js
  4. +13
    -0
      test/swagger-ui-dist-package/absolute-path.js

+ 1
- 1
package.json View File

@@ -32,7 +32,7 @@
"test": "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-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": {
"babel-polyfill": "^6.23.0",


+ 14
- 0
swagger-ui-dist-package/absolute-path.js View 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()

+ 3
- 5
swagger-ui-dist-package/index.js View File

@@ -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
- 0
test/swagger-ui-dist-package/absolute-path.js View 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)
})
})
})

Loading…
Cancel
Save