Skip to content

Commit

Permalink
Tsify asm-docs-tests to typescript with utils (#4670)
Browse files Browse the repository at this point in the history
  • Loading branch information
junlarsen committed Jan 31, 2023
1 parent 86317c7 commit 39b81c9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/AddingAssemblyDocumentation.md
Expand Up @@ -76,4 +76,4 @@ Finally we want to tell CE that the new documentation provider exists. This is d
## 4. Testing

Testing new assembly documentation providers is really easy. It is just a matter of modifying the `TEST_MATRIX` variable
found in the `/test/handlers/asm-docs-tests.js` file.
found in the `/test/handlers/asm-docs-tests.ts` file.
35 changes: 31 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -101,6 +101,7 @@
"devDependencies": {
"@babel/preset-typescript": "^7.16.5",
"@types/bootstrap": "^5.1.6",
"@types/chai": "^4.3.4",
"@types/express": "^4.17.14",
"@types/fs-extra": "^9.0.13",
"@types/jquery": "^3.5.10",
Expand Down
Expand Up @@ -29,7 +29,7 @@ import {withAssemblyDocumentationProviders} from '../../lib/handlers/assembly-do
import {chai} from '../utils';

/** Test matrix of architecture to [opcode, tooptip, html, url] */
export const TEST_MATRIX = {
export const TEST_MATRIX: Record<PropertyKey, [string, string, string, string][]> = {
6502: [
[
'lda',
Expand Down Expand Up @@ -82,7 +82,7 @@ export const TEST_MATRIX = {
};

describe('Assembly Documentation API', () => {
let app;
let app: express.Express;

before(() => {
app = express();
Expand Down
11 changes: 6 additions & 5 deletions test/utils.js → test/utils.ts
Expand Up @@ -26,12 +26,14 @@ import path from 'path';
import {fileURLToPath} from 'url';

import chai from 'chai';
import fs from 'fs-extra';

import {CompilationEnvironment} from '../lib/compilation-env';
import {CompilationQueue} from '../lib/compilation-queue';
import {CompilerProps, fakeProps} from '../lib/properties';

export function makeCompilationEnvironment(options) {
// TODO: Find proper type for options
export function makeCompilationEnvironment(options: Record<string, any>): CompilationEnvironment {
const compilerProps = new CompilerProps(options.languages, fakeProps(options.props || {}));
const compilationQueue = options.queue || new CompilationQueue(options.concurrency || 1, options.timeout);
return new CompilationEnvironment(compilerProps, compilationQueue, options.doCache);
Expand All @@ -44,10 +46,9 @@ export const should = chai.should();
*/
export const TEST_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)));

export function resolvePathFromTestRoot(...args) {
export function resolvePathFromTestRoot(...args: string[]): string {
return path.resolve(TEST_ROOT, ...args);
}

export {default as fs} from 'fs-extra';
export {default as chai} from 'chai';
export {default as path} from 'path';
// eslint-disable-next-line -- do not rewrite exports
export { chai, path, fs }
1 change: 1 addition & 0 deletions tsconfig.backend.json
Expand Up @@ -11,6 +11,7 @@
/* Code generation */
"outDir": "./out/dist",
"typeRoots": ["./typings", "./node_modules/@types"],
"types": ["mocha", "chai", "chai-http"],
/* Other options */
"allowJs": true
}
Expand Down

0 comments on commit 39b81c9

Please sign in to comment.