Skip to content

Commit 844f98c

Browse files
authored
Merge pull request #98 from andrewbranch/graphql-testing
Add GraphQL testing infrastructure
2 parents ffbfe2c + d22f6db commit 844f98c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+35608
-5622
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ jobs:
3030
with:
3131
node-version: ${{ matrix.node }}
3232
- name: install
33-
run: npm ci
33+
run: yarn install --frozen-lockfile
3434
- name: test
35-
run: npm test
35+
run: yarn test
3636
publish:
3737
if: github.event_name == 'release'
3838
needs: build_test
@@ -45,9 +45,9 @@ jobs:
4545
node-version: '12'
4646
registry-url: 'https://registry.npmjs.org'
4747
- name: install
48-
run: npm ci
48+
run: yarn install --frozen-lockfile
4949
- name: build
50-
run: npm run build
50+
run: yarn build
5151
- name: publish production
5252
run: npm publish
5353
env:
@@ -64,9 +64,9 @@ jobs:
6464
node-version: '12'
6565
registry-url: 'https://registry.npmjs.org'
6666
- name: install
67-
run: npm ci
67+
run: yarn install --frozen-lockfile
6868
- name: build
69-
run: npm run build
69+
run: yarn build
7070
- name: publish alpha
7171
run: |
7272
version=`node .github/workflows/getVersion.js 3.0.0`

CONTRIBUTING.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ PRs introducing new ideas are always welcome, but might be declined if opened wi
1010

1111
## Local development setup
1212

13-
Prerequisites: development is supported on the current [Node LTS](https://nodejs.org/).
13+
Prerequisites: development is supported on the current [Node LTS](https://nodejs.org/). Yarn is probably required to run all tests correctly, because npm fails to deduplicate certain dependencies which causes issues for running the GraphQL tests.
1414

1515
1. Fork and clone the repo.
16-
2. Run `npm install`
16+
2. Run `yarn`
1717

18-
Running `npm install` should automatically initialize or update the [vscode](./vscode) submodule, generate `src/graphql/schema.d.ts`, and populate [`lib/grammars`](lib/grammars) and [`lib/themes`](lib/themes). If any of these things are missing, you’ll get errors when you try to run things later. You can rerun these steps with `npm run build`.
18+
Running `yarn` should automatically initialize or update the [vscode](./vscode) submodule, generate `src/graphql/schema.d.ts`, and populate [`lib/grammars`](lib/grammars) and [`lib/themes`](lib/themes). If any of these things are missing, you’ll get errors when you try to run things later. You can rerun these steps with `yarn build`.
1919

2020
## Tests
2121

22-
To run tests, run `npm test`. You can use Jest CLI options after a `--` separator. For example, to run just the test named “code-fence-meta”, use `npm test -- -t code-fence-meta`.
22+
To run tests, run `yarn test`. You can use any Jest CLI options. For example, to run just the test named “code-fence-meta”, use `yarn test -t code-fence-meta`.
2323

24-
Most tests are either Jest snapshot tests or HTML baseline tests against a known-good source ([`test/integration/cases/baselines`](test/integration/cases/baselines)). To update the snapshots and baselines, run `npm test -- -u`.
24+
Most tests are either Jest snapshot tests or HTML baseline tests against a known-good source ([`test/html/cases/baselines`](test/html/baselines)). To update the snapshots and baselines, run `yarn test -u`.
2525

26-
Most new tests can be integration tests. To write one, create a new folder in `test/integration/cases`, then put a Markdown file named `test.md` inside. If you want to run the plugin with custom options, place an `options.js` file whose `module.exports` is the options object to be passed to the plugin. Then, when you next run `npm test`, the baseline will be created and opened in a browser so you can view the resulting HTML. If it looks right, commit it and you’re done. If it looks wrong, you can overwrite the bad baseline by running `npm test -- -u -t name-of-test` after you’ve made changes to fix your code.
26+
Most new tests can be baseline tests. To write one, create a new folder in `test/cases`, then put a Markdown file named `test.md` inside. If you want to run the plugin with custom options, place an `options.js` file whose `module.exports` is the options object to be passed to the plugin. Then, when you next run `yarn test`, the baseline will be created and opened in a browser so you can view the resulting HTML. If it looks right, commit it and you’re done. If it looks wrong, you can overwrite the bad baseline by running `yarn test -u -t name-of-test` after you’ve made changes to fix your code.
27+
28+
Tests inside `test/cases` also generate a snapshot of a GraphQL query for the structured syntax highlighting data the plugin generates. The snapshot has a lot of data, so if you’re adding a new test case, don’t worry about manually inspecting every line of the added snapshot. They exist mostly to detect regressions, so if the snapshot looks plausibly correct, go ahead and commit it.
2729

2830
## Debugging
2931

@@ -34,7 +36,7 @@ VS Code launch scripts have been provided, so you can debug the tests or the [ex
3436
When you’ve made changes you’re happy with, ensure that you have
3537

3638
- Added a test if appropriate,
37-
- Formatted your changes through Prettier with `npm run format`,
39+
- Formatted your changes through Prettier with `yarn format`,
3840
- Maintained good JSDoc type annotations to the best of your ability.
3941

40-
This project is written in plain JavaScript, but uses TypeScript to type-check via JSDoc annotations. After tests, type checking runs (and can be run alone with `npm run check`). If types are new to you, or you have trouble getting type checking to pass, that’s ok! I’ll help you in your PR if necessary. Type checking is a great way to catch errors early, but I don’t want it to be an impediment for anyone’s contribution.
42+
This project is written in plain JavaScript, but uses TypeScript to type-check via JSDoc annotations. After tests, type checking runs (and can be run alone with `yarn check`). If types are new to you, or you have trouble getting type checking to pass, that’s ok! I’ll help you in your PR if necessary. Type checking is a great way to catch errors early, but I don’t want it to be an impediment for anyone’s contribution.

gatsby-node.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const logger = require('loglevel');
2-
const { getChildNodes } = require('./src/cacheUtils');
2+
const { getChildBlockNodes, getChildSpanNodes } = require('./src/cacheUtils');
33
const highlight = require('./src/graphql/highlight');
44
const stylesheet = require('./src/graphql/stylesheet');
55

@@ -62,7 +62,8 @@ exports.createResolvers = ({
6262
* @param {boolean=} stop
6363
*/
6464
async function getFromCache(type, cache, source, context, stop) {
65-
const childNodes = await getChildNodes(cache, source.id, source.internal.contentDigest);
65+
const get = type === 'GRVSCCodeBlock' ? getChildBlockNodes : getChildSpanNodes;
66+
const childNodes = await get(cache, source.id, source.internal.contentDigest);
6667
// Hack alert: ensure plugin has been run by querying htmlAst,
6768
// which is set via `setFieldsOnGraphQLNodeType` by gatsby-transformer-remark,
6869
// therefore might not have been run before this resolver runs.
@@ -77,7 +78,7 @@ async function getFromCache(type, cache, source, context, stop) {
7778
type: 'MarkdownRemark',
7879
firstOnly: true,
7980
});
80-
return getFromCache(cache, source, context, true);
81+
return getFromCache(type, cache, source, context, true);
8182
}
8283
if (!childNodes) {
8384
logger.error(

0 commit comments

Comments
 (0)