forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRawScriptLoader.test.ts
More file actions
29 lines (24 loc) · 921 Bytes
/
RawScriptLoader.test.ts
File metadata and controls
29 lines (24 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { assert } from 'chai';
import RawScriptLoader = require('./../RawScriptLoader');
function wrapResult(result: string): string {
return `var exports = {};
eval(${result});
exports;`;
}
describe('RawScriptLoader', () => {
it('follows the Webpack loader interface', () => {
assert.isDefined(RawScriptLoader);
assert.isFunction(RawScriptLoader);
});
it('returns a string', () => {
assert.isString(RawScriptLoader(''));
});
it('correctly sets exported objects', () => {
const testScript: string = 'var x = 123; this.exportedObject = x;';
// eslint-disable-next-line no-eval
const exports: { exportedObject: number } = eval(wrapResult(RawScriptLoader(testScript)));
assert.equal(exports.exportedObject, 123);
});
});