Skip to content

Commit

Permalink
Increase E2E coverage for JS tests (OctoLinker#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck authored Jan 11, 2020
1 parent 9d91d2f commit be3f657
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ It also works within JSON files:
}
```

There is also a `OctoLinkerResolveAbove` annotation. This might be needed for situation where the comment doesn't work in the line above for whatever reason.

```js
require('fs')
// @OctoLinkerResolveAbove(https://nodejs.org/api/fs.html)
```

Before we invoke [jest](https://github.com/facebook/jest), we scan the fixtures folder for the annotations described above and write a file named `fixtures.json` to the disk. This JSON file then gets loaded by our actual test file (https://github.com/OctoLinker/OctoLinker/blob/master/e2e/automated.test.js) to scaffold those tests on-the-fly.


Expand Down
28 changes: 27 additions & 1 deletion e2e/fixtures/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,33 @@
require('fs');

// @OctoLinkerResolve(https://github.com/lodash/lodash)
require('lodash');
require("lodash");

// @OctoLinkerResolve(https://github.com/facebook/react)
require('react');

// @OctoLinkerResolve(https://nodejs.org/api/http.html)
const http = require('http');

// @OctoLinkerResolve(https://nodejs.org/api/cluster.html)
const { cluster } = require('cluster');

// @OctoLinkerResolve(https://nodejs.org/api/path.html)
import path from "path";

// @OctoLinkerResolve(https://nodejs.org/api/url.html)
import url from 'url';

// @OctoLinkerResolve(https://deno.land/x/std/fs/mod.ts)
import * as fs from "https://deno.land/x/std/fs/mod.ts";

// @OctoLinkerResolve(https://nodejs.org/api/os.html)
import { os } from 'os';

import {
foo
} from 'dns';
// @OctoLinkerResolveAbove(https://nodejs.org/api/dns.html)

// @OctoLinkerResolve(https://nodejs.org/api/net.html)
export { default as net } from 'net';
4 changes: 3 additions & 1 deletion e2e/generate-fixtures-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ function findTests(contents) {
let lineNumber = index + 2;
if (file.endsWith('.md')) {
lineNumber = undefined;
} else if (line.includes('@OctoLinkerResolveAbove')) {
lineNumber = index;
}

const targetUrl = line
.match(/@OctoLinkerResolve\((.*?)\)/)[1]
.match(/@OctoLinkerResolve(Above)?\((.*?)\)/)[2]
.replace('<root>', '');

const filePath = file.replace(__dirname, '');
Expand Down

0 comments on commit be3f657

Please sign in to comment.