Skip to content

Commit

Permalink
add test that compare origin and this loader work result
Browse files Browse the repository at this point in the history
  • Loading branch information
k.stoyanov committed Nov 14, 2023
1 parent 6cad3ba commit 7e22322
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const webpack = require('webpack');
const { createFsFromVolume, Volume } = require('memfs');

const compiler = (entry) => {
const compiler = ({ entry, loader }) => {
const compiler = webpack({
mode: 'development',
context: __dirname,
Expand All @@ -20,7 +20,7 @@ const compiler = (entry) => {
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
use: {
loader: '@evo/graphql-tag-loader',
loader,
},
},
],
Expand Down
20 changes: 18 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const compiler = require('./compiler');

describe('Loader test', () => {
it('Should return file with some strings', async () => {
const stats = await compiler('./graphql/ProductQuery.graphql');
const stats = await compiler({ entry: './graphql/ProductQuery.graphql', loader: '@evo/graphql-tag-loader' });

const output = stats.toJson({ source: true }).modules[0].source;
expect(
Expand All @@ -18,7 +18,7 @@ describe('Loader test', () => {
});

it('Should be valid query', async () => {
const stats = await compiler('./graphql/CategoryQuery.graphql');
const stats = await compiler({ entry: './graphql/CategoryQuery.graphql', loader: '@evo/graphql-tag-loader' });

const output = stats.toJson({ source: true }).modules[0].source;
const result = eval(output);
Expand All @@ -27,4 +27,20 @@ describe('Loader test', () => {
expect(result.definitions[0].kind).toBe('OperationDefinition');
expect(result.definitions[1].kind).toBe('FragmentDefinition');
});

it('Should be the same result of function call in original loader and this loader', async () => {
const originLoaderStats = await compiler({
entry: './graphql/CategoryQuery.graphql',
loader: 'graphql-tag/loader',
});
const evoLoaderStats = await compiler({
entry: './graphql/CategoryQuery.graphql',
loader: '@evo/graphql-tag-loader',
});
const originLoaderOutput = originLoaderStats.toJson({ source: true }).modules[0].source;
const evoLoaderOutput = evoLoaderStats.toJson({ source: true }).modules[0].source;
const originLoaderResult = eval(originLoaderOutput);
const evoLoaderResult = eval(evoLoaderOutput);
expect(JSON.stringify(evoLoaderResult)).toBe(JSON.stringify(originLoaderResult))
});
});

0 comments on commit 7e22322

Please sign in to comment.