-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
91 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
exports.default = function (configDirPath) { | ||
var headHtmlPath = _path2.default.resolve(configDirPath, 'head.html'); | ||
var headHtml = ''; | ||
if (_fs2.default.existsSync(headHtmlPath)) { | ||
headHtml = _fs2.default.readFileSync(headHtmlPath, 'utf8'); | ||
} | ||
|
||
return headHtml; | ||
}; | ||
|
||
var _path = require('path'); | ||
|
||
var _path2 = _interopRequireDefault(_path); | ||
|
||
var _fs = require('fs'); | ||
|
||
var _fs2 = _interopRequireDefault(_fs); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { describe, it, beforeEach, afterEach } = global; | ||
import { expect } from 'chai'; | ||
import getHeadHtml from '../get_head_html'; | ||
import mock from 'mock-fs'; | ||
|
||
const HEAD_HTML_CONTENTS = '<script>console.log("custom script!");</script>'; | ||
|
||
describe('server.getHeadHtml', () => { | ||
describe('when .storybook/head.html does not exist', () => { | ||
beforeEach(() => { | ||
mock({ | ||
config: {}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
mock.restore(); | ||
}); | ||
|
||
it('return an empty string', () => { | ||
const result = getHeadHtml('./config'); | ||
expect(result).to.be.equal(''); | ||
}); | ||
}); | ||
|
||
describe('when .storybook/head.html exists', () => { | ||
beforeEach(() => { | ||
mock({ | ||
config: { | ||
'head.html': HEAD_HTML_CONTENTS, | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
mock.restore(); | ||
}); | ||
|
||
it('return the contents of the file', () => { | ||
const result = getHeadHtml('./config'); | ||
expect(result).to.be.equal(HEAD_HTML_CONTENTS); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
export default function (configDirPath) { | ||
const headHtmlPath = path.resolve(configDirPath, 'head.html'); | ||
let headHtml = ''; | ||
if (fs.existsSync(headHtmlPath)) { | ||
headHtml = fs.readFileSync(headHtmlPath, 'utf8'); | ||
} | ||
|
||
return headHtml; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters