Skip to content

Commit

Permalink
separateOperations-test: refactor tests to look like snapshots (graph…
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored and yaacovCR committed Apr 11, 2021
1 parent 27f495e commit bcf2317
Showing 1 changed file with 89 additions and 92 deletions.
181 changes: 89 additions & 92 deletions src/utilities/__tests__/separateOperations-test.js
Expand Up @@ -3,6 +3,8 @@ import { describe, it } from 'mocha';

import dedent from '../../__testUtils__/dedent';

import mapValue from '../../jsutils/mapValue';

import { parse } from '../../language/parser';
import { print } from '../../language/printer';

Expand Down Expand Up @@ -47,67 +49,64 @@ describe('separateOperations', () => {
}
`);

const separatedASTs = separateOperations(ast);

expect(separatedASTs).to.have.all.keys('', 'One', 'Two');

expect(print(separatedASTs[''])).to.equal(dedent`
{
...Y
...X
}
fragment X on T {
fieldX
}
fragment Y on T {
fieldY
}
`);

expect(print(separatedASTs.One)).to.equal(dedent`
query One {
foo
bar
...A
...X
}
fragment A on T {
field
...B
}
fragment X on T {
fieldX
}
fragment B on T {
something
}
`);

expect(print(separatedASTs.Two)).to.equal(dedent`
fragment A on T {
field
...B
}
query Two {
...A
...Y
baz
}
fragment Y on T {
fieldY
}
fragment B on T {
something
}
`);
const separatedASTs = mapValue(separateOperations(ast), print);
expect(separatedASTs).to.deep.equal({
'': dedent`
{
...Y
...X
}
fragment X on T {
fieldX
}
fragment Y on T {
fieldY
}
`,
One: dedent`
query One {
foo
bar
...A
...X
}
fragment A on T {
field
...B
}
fragment X on T {
fieldX
}
fragment B on T {
something
}
`,
Two: dedent`
fragment A on T {
field
...B
}
query Two {
...A
...Y
baz
}
fragment Y on T {
fieldY
}
fragment B on T {
something
}
`,
});
});

it('survives circular dependencies', () => {
Expand All @@ -129,36 +128,34 @@ describe('separateOperations', () => {
}
`);

const separatedASTs = separateOperations(ast);

expect(separatedASTs).to.have.all.keys('One', 'Two');

expect(print(separatedASTs.One)).to.equal(dedent`
query One {
...A
}
fragment A on T {
...B
}
fragment B on T {
...A
}
`);

expect(print(separatedASTs.Two)).to.equal(dedent`
fragment A on T {
...B
}
fragment B on T {
...A
}
query Two {
...B
}
`);
const separatedASTs = mapValue(separateOperations(ast), print);
expect(separatedASTs).to.deep.equal({
One: dedent`
query One {
...A
}
fragment A on T {
...B
}
fragment B on T {
...A
}
`,
Two: dedent`
fragment A on T {
...B
}
fragment B on T {
...A
}
query Two {
...B
}
`,
});
});
});

0 comments on commit bcf2317

Please sign in to comment.