Skip to content

Commit

Permalink
Avoid using direct eval in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jan 29, 2021
1 parent 159979b commit 1dc4a23
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe('gql', () => {
sameFragment,
);
const module = { exports: Object.create(null) };
eval(jsSource);

Function("module", jsSource)(module);

const document = gql`query { ...SomeFragmentName } ${module.exports}`;
assert.equal(document.kind, 'Document');
Expand All @@ -42,7 +43,7 @@ describe('gql', () => {
it('parses queries through webpack loader', () => {
const jsSource = loader.call({ cacheable() {} }, '{ testQuery }');
const module = { exports: Object.create(null) };
eval(jsSource);
Function("module", jsSource)(module);
assert.equal(module.exports.kind, 'Document');
});

Expand All @@ -51,7 +52,7 @@ describe('gql', () => {
query Q1 { testQuery }
`);
const module = { exports: Object.create(null) };
eval(jsSource);
Function("module", jsSource)(module);

assert.equal(module.exports.kind, 'Document');
assert.exists(module.exports.Q1);
Expand All @@ -64,8 +65,7 @@ describe('gql', () => {
query Q1 { testQuery }
`);
const module = { exports: Object.create(null) };
eval(jsSource);

Function("module", jsSource)(module);
assert.deepEqual(module.exports.definitions, module.exports.Q1.definitions);
});

Expand All @@ -75,7 +75,7 @@ describe('gql', () => {
query Q2 { testQuery2 }
`);
const module = { exports: Object.create(null) };
eval(jsSource);
Function("module", jsSource)(module);

assert.exists(module.exports.Q1);
assert.exists(module.exports.Q2);
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('gql', () => {
query Q3 { test Query3 }
`);
const module = { exports: Object.create(null) };
eval(jsSource);
Function("module", jsSource)(module);

assert.notExists(module.exports.Q2.Q1);
assert.notExists(module.exports.Q3.Q1);
Expand All @@ -123,7 +123,7 @@ describe('gql', () => {
}
`);
const module = { exports: Object.create(null) };
eval(jsSource);
Function("module", jsSource)(module);

assert.exists(module.exports.Q1);
assert.exists(module.exports.Q2);
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('gql', () => {
`);

const module = { exports: Object.create(null) };
eval(jsSource);
Function("module", jsSource)(module);

assert.exists(module.exports.Q1);
assert.exists(module.exports.Q2);
Expand Down Expand Up @@ -203,8 +203,7 @@ describe('gql', () => {
lastName
}`;
};
assert.equal(typeof require, 'function');
eval(jsSource);
Function("module,require", jsSource)(module, require);
assert.equal(module.exports.kind, 'Document');
const definitions = module.exports.definitions;
assert.equal(definitions.length, 2);
Expand Down Expand Up @@ -236,8 +235,7 @@ describe('gql', () => {
f2
}`;
};
assert.equal(typeof require, 'function');
eval(jsSource);
Function("module,require", jsSource)(module, require);

assert.exists(module.exports.Q1);
assert.exists(module.exports.Q2);
Expand All @@ -263,7 +261,7 @@ describe('gql', () => {
}`;
const jsSource = loader.call({ cacheable() {} }, query);
const module = { exports: Object.create(null) };
eval(jsSource);
Function("module", jsSource)(module);
assert.equal(module.exports.kind, 'Document');
done();
});
Expand Down Expand Up @@ -400,7 +398,7 @@ describe('gql', () => {
): DocumentNode | null => {
const jsSource = loader.call({ cacheable() {} }, query);
const module = { exports: Object.create(null) };
eval(jsSource);
Function("require,module", jsSource)(require, module);
return module.exports;
}

Expand Down

0 comments on commit 1dc4a23

Please sign in to comment.