Skip to content

Commit

Permalink
fix: local jest no cm6, ci with cm6
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Jun 21, 2023
1 parent 0256ed7 commit 9940064
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 430 deletions.
4 changes: 2 additions & 2 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ module.exports = (dir, env = 'jsdom') => {
'^codemirror-graphql\\/esm([^]+)': `${__dirname}/packages/codemirror-graphql/src/$1`,
'^codemirror-graphql\\/cjs([^]+)': `${__dirname}/packages/codemirror-graphql/src/$1`,
// relies on compilation
// '^cm6-graphql\\/([^]+)': `${__dirname}/packages/cm6-graphql/src/$1`,
'^cm6-graphql\\/src\\/([^]+)': `${__dirname}/packages/cm6-graphql/dist/$1`,
'^example-([^/]+)': `${__dirname}/examples/$1/src`,
'^-!svg-react-loader.*$': '<rootDir>/resources/jest/svgImportMock.js'
},
testMatch: ['**/*[-.](spec|test).[jt]s?(x)', '!**/cypress/**'],
testEnvironment: env,
testPathIgnorePatterns: ['node_modules', 'dist', 'cypress', 'packages/cm6-graphql'],
testPathIgnorePatterns: ['node_modules', 'dist', 'cypress'],
collectCoverageFrom: ['**/src/**/*.{js,jsx,ts,tsx}'],
coveragePathIgnorePatterns: [
'dist',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"build": "yarn build:clean && yarn build:cm6-graphql && yarn build:packages && yarn build:graphiql-react && yarn build:graphiql-plugin-explorer && yarn build:graphiql-plugin-code-exporter && yarn build:graphiql",
"build-bundles": "yarn prebuild-bundles && wsrun -p -m -s build-bundles",
"build-bundles-clean": "rimraf '{packages,examples,plugins}/**/{bundle,cdn,webpack}' && yarn workspace graphiql run build-bundles-clean",
"build-clean": "wsrun -m build-clean && rimraf packages/**/{esm,cjs,dist,types}",
"build-clean": "wsrun -m build-clean",
"build-demo": "wsrun -m -s build-demo",
"build-docs": "rimraf 'packages/graphiql/typedoc' && typedoc 'packages'",
"build:clean": "yarn tsc --clean && yarn tsc --clean resources/tsconfig.graphiql.json",
Expand All @@ -54,7 +54,7 @@
"e2e:build": "yarn build && yarn workspace graphiql build-bundles-min",
"eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --max-warnings=0 --cache .",
"format": "yarn eslint --fix && yarn pretty",
"jest": "jest",
"jest": "jest --testPathIgnorePatterns cm6-graphql",
"license-check": "jsgl --local ./",
"lint": "yarn eslint && yarn lint-check && yarn pretty-check && yarn lint-cspell",
"lint-check": "eslint-config-prettier .eslintrc.js",
Expand All @@ -75,7 +75,7 @@
"start-monaco": "yarn workspace example-monaco-graphql-webpack start",
"t": "yarn run test",
"test": "yarn jest",
"test:ci": "yarn test && yarn workspace cm6-graphql test",
"test:ci": "yarn build:cm6-graphql && jest",
"test:coverage": "yarn jest --coverage",
"test:watch": "yarn jest --watch",
"tsc": "tsc --build"
Expand All @@ -100,7 +100,7 @@
"@types/codemirror": "^0.0.90",
"@types/express": "^4.17.11",
"@types/fetch-mock": "^7.3.2",
"@types/jest": "^26.0.22",
"@types/jest": "^29.5.2",
"@types/node": "^16.18.4",
"@types/prettier": "^2.7.0",
"@types/ws": "^7.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cm6-graphql/__tests__/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable jest/expect-expect */
import { graphqlLanguage } from '../dist';
import { graphqlLanguage } from '../dist/index.js';
import { fileTests } from '@lezer/generator/dist/test';

import * as fs from 'node:fs';
Expand Down
3 changes: 3 additions & 0 deletions packages/cm6-graphql/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const base = require('../../jest.config.base')(__dirname);

// remove the ignore line for cm6-graphql
base.testPathIgnorePatterns.pop()

module.exports = {
...base,
transformIgnorePatterns: [
Expand Down
3 changes: 1 addition & 2 deletions packages/cm6-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "GraphQL language support for CodeMirror 6",
"scripts": {
"build": "cm-buildhelper src/index.ts",
"prepare": "yarn build",
"test": "yarn build && yarn test"
"prepare": "yarn build"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/src/explorer/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
isInterfaceType,
isObjectType,
} from 'graphql';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { FocusEventHandler, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Combobox } from '@headlessui/react';
import { MagnifyingGlassIcon } from '../../icons';
import { useSchemaContext } from '../../schema';
Expand Down Expand Up @@ -63,7 +63,7 @@ export function Search() {
[push],
);
const [isFocused, setIsFocused] = useState(false);
const handleFocus = useCallback((e: any) => {
const handleFocus: FocusEventHandler = useCallback((e) => {
setIsFocused(e.type === 'focus');
}, []);

Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/cypress/e2e/docs.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { version } from 'graphql/version';

beforeEach(() => {
cy.visit('');
cy.visit('/');
});

describe('GraphiQL DocExplorer - button', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/graphiql/cypress/e2e/errors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { version } from 'graphql';

describe('Errors', () => {
it('Should show an error when the HTTP request fails', () => {
cy.visit('?http-error=true');
cy.visit('/?http-error=true');
cy.assertQueryResult({
errors: [
{
Expand All @@ -21,14 +21,14 @@ describe('Errors', () => {
});

it('Should show an error when introspection fails', () => {
cy.visit('?graphql-error=true');
cy.visit('/?graphql-error=true');
cy.assertQueryResult({
errors: [{ message: 'Something unexpected happened...' }],
});
});

it('Should show an error when the schema is invalid', () => {
cy.visit('?bad=true');
cy.visit('/?bad=true');
/**
* We can't use `cy.assertQueryResult` here because the stack contains line
* and column numbers of the `graphiql.min.js` bundle which are not stable.
Expand Down
106 changes: 4 additions & 102 deletions packages/graphiql/cypress/e2e/history.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ describe('history', () => {

});
it('defaults to closed history panel', () => {
cy.visit('');
cy.visit('/');

cy.get('.graphiql-history').should('not.exist');
});

it('will save history item even when history panel is closed', () => {
cy.visit('?query={test}');
cy.visit('/?query={test}');
cy.clickExecuteQuery();
cy.get('button[aria-label="Show History"]').click();
cy.get('ul.graphiql-history-items').should('have.length', 1);
});

it('will save history item even when history panel is closed', () => {
cy.visit('?query={test}');
cy.visit('/?query={test}');
cy.clickExecuteQuery();
cy.get('button[aria-label="Show History"]').click();
cy.get('ul.graphiql-history-items li').should('have.length', 1);
Expand Down Expand Up @@ -87,102 +87,4 @@ describe('history', () => {
cy.get('ul.graphiql-history-items li').should('have.length', 2);
});

// it('will save query if variables are different', async () => {
// const { getByLabelText, container } = render(
// <GraphiQL
// fetcher={noOpFetcher}
// operationName={mockOperationName1}
// query={mockQuery1}
// variables={mockVariables1}
// headers={mockHeaders1}
// />,
// );

// act(() => {
// fireEvent.click(getByLabelText('Show History'));
// });

// const executeQueryButton = getByLabelText('Execute query (Ctrl-Enter)');

// act(() => {
// fireEvent.click(executeQueryButton);
// });

// await waitFor(() => {
// expect(
// container.querySelectorAll('.graphiql-history-item'),
// ).toHaveLength(1);
// });

// act(() => {
// fireEvent.change(
// container.querySelector('[aria-label="Variables"] .mockCodeMirror'),
// {
// target: { value: mockVariables2 },
// },
// );
// });

// act(() => {
// fireEvent.click(executeQueryButton);
// });

// await waitFor(() => {
// expect(
// container.querySelectorAll('.graphiql-history-item'),
// ).toHaveLength(2);
// });
// });

// it('will save query if headers are different', async () => {
// const { getByLabelText, getByText, container } = render(
// <GraphiQL
// fetcher={noOpFetcher}
// operationName={mockOperationName1}
// query={mockQuery1}
// variables={mockVariables1}
// headers={mockHeaders1}
// isHeadersEditorEnabled
// />,
// );

// act(() => {
// fireEvent.click(getByLabelText('Show History'));
// });

// const executeQueryButton = getByLabelText('Execute query (Ctrl-Enter)');

// act(() => {
// fireEvent.click(executeQueryButton);
// });

// await waitFor(() => {
// expect(
// container.querySelectorAll('.graphiql-history-item'),
// ).toHaveLength(1);
// });

// act(() => {
// fireEvent.click(getByText('Headers'));
// });

// act(() => {
// fireEvent.change(
// container.querySelector('[aria-label="Headers"] .mockCodeMirror'),
// {
// target: { value: mockHeaders2 },
// },
// );
// });

// act(() => {
// fireEvent.click(executeQueryButton);
// });

// await waitFor(() => {
// expect(
// container.querySelectorAll('.graphiql-history-item'),
// ).toHaveLength(2);
// });
// });
}); // history
});
4 changes: 2 additions & 2 deletions packages/graphiql/cypress/e2e/init.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('GraphiQL On Initialization', () => {
'.graphiql-response',
'.graphiql-editor-tool',
];
cy.visit('');
cy.visit('/');
cy.get('.graphiql-query-editor').contains('# Welcome to GraphiQL');
for (const cSelector of containers) {
cy.get(cSelector).should('be.visible');
Expand All @@ -49,7 +49,7 @@ describe('GraphiQL On Initialization', () => {
cy.assertQueryResult(mockSuccess);
});
it('Shows the expected error when the schema is invalid', () => {
cy.visit('?bad=true');
cy.visit('/?bad=true');
cy.get('section.result-window').should(element => {
expect(element.get(0).innerText).to.contain('Names must');
});
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql/cypress/e2e/keyboard.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('GraphiQL keyboard interactions', () => {
it('Does not prevent the escape key from being handled outside the editor', () => {
cy.visit('');
cy.visit('/');
const mockFn = cy.stub().as('escapeHandler');
cy.document().then(doc => {
doc.addEventListener('keydown', event => {
Expand All @@ -16,7 +16,7 @@ describe('GraphiQL keyboard interactions', () => {
});

it('Does prevent the escape key from being handled outside the editor if closing the autocomplete dialog', () => {
cy.visit('');
cy.visit('/');
const mockFn = cy.stub().as('escapeHandler');
cy.document().then(doc => {
doc.addEventListener('keydown', event => {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/cypress/e2e/tabs.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Tabs', () => {
it('Should store editor contents when switching between tabs', () => {
cy.visit('?query=');
cy.visit('/?query=');

// Assert that no tab visible when there's only one session
cy.get('#graphiql-session-tab-0').should('not.exist');
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-language-service-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"graphql": "^15.5.0 || ^16.0.0"
},
"dependencies": {
"@types/yargs": "^16.0.5",
"@babel/polyfill": "^7.12.1",
"graphql-language-service": "^5.1.7-alpha.0",
"graphql-language-service-server": "^2.11.2-alpha.0",
Expand Down
Loading

0 comments on commit 9940064

Please sign in to comment.