Files
superset2/superset/assets/spec/javascripts/modules/sandbox_spec.jsx
Maxime Beauchemin 69195f8d2d Introduce Javascript controls (#4076)
* Introduce Javascript controls

This allows power-users to perform intricate transformations on data and
objects using javascript code.

The operations allowed are "sanboxed" or limited using node's vm
`runInNewContext`
https://nodejs.org/api/vm.html#vm_vm_runinnewcontext_code_sandbox_options

For now I'm only enabling in the line chart visualization, but the plan
would be to go towards offering more power to people who can write some
JS moving forward.

* Not applied
2017-12-20 21:24:35 -08:00

18 lines
585 B
JavaScript

import { it, describe } from 'mocha';
import { expect } from 'chai';
import sandboxedEval from '../../../javascripts/modules/sandbox';
describe('sandboxedEval', () => {
it('works like a basic eval', () => {
expect(sandboxedEval('100')).to.equal(100);
expect(sandboxedEval('v => v * 2')(5)).to.equal(10);
});
it('d3 is in context and works', () => {
expect(sandboxedEval("l => _.find(l, s => s === 'bar')")(['foo', 'bar'])).to.equal('bar');
});
it('passes context as expected', () => {
expect(sandboxedEval('foo', { foo: 'bar' })).to.equal('bar');
});
});