mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
Tsify a small handful of tests (#4765)
This commit is contained in:
@@ -35,7 +35,7 @@ import * as utils from '../utils';
|
||||
|
||||
import {ApiHandler} from './api';
|
||||
|
||||
type HandlerConfig = {
|
||||
export type HandlerConfig = {
|
||||
compileHandler: any;
|
||||
clientOptionsHandler: any;
|
||||
storageHandler: StorageBase;
|
||||
|
||||
@@ -71,8 +71,8 @@ export function get(base: string, property: string, defaultValue?: unknown): unk
|
||||
|
||||
export type RawPropertiesGetter = typeof get;
|
||||
|
||||
export function parseProperties(blob, name) {
|
||||
const props = {};
|
||||
export function parseProperties(blob: string, name) {
|
||||
const props: Record<string, PropertyValue> = {};
|
||||
for (const [index, lineOrig] of blob.split('\n').entries()) {
|
||||
const line = lineOrig.replace(/#.*/, '').trim();
|
||||
if (!line) continue;
|
||||
@@ -82,7 +82,7 @@ export function parseProperties(blob, name) {
|
||||
continue;
|
||||
}
|
||||
const prop = split[1].trim();
|
||||
let val = split[2].trim();
|
||||
let val: string | number | boolean = split[2].trim();
|
||||
// hack to avoid applying toProperty to version properties
|
||||
// so that they're not parsed as numbers
|
||||
if (!prop.endsWith('.version') && !prop.endsWith('.semver')) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import {unwrap} from '../lib/assert';
|
||||
import * as properties from '../lib/properties';
|
||||
|
||||
import {should} from './utils';
|
||||
@@ -170,9 +171,10 @@ describe('Properties blob parsing', () => {
|
||||
'hello = test \n' +
|
||||
'etc=123\n' +
|
||||
'mybool=false\n',
|
||||
'<test props>',
|
||||
);
|
||||
props.hello.should.equal('test');
|
||||
props.etc.should.equal(123);
|
||||
props.mybool.should.equal(false);
|
||||
unwrap(props.hello).should.equal('test');
|
||||
unwrap(props.etc).should.equal(123);
|
||||
unwrap(props.mybool).should.equal(false);
|
||||
});
|
||||
});
|
||||
@@ -24,7 +24,9 @@
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import {unwrap} from '../lib/assert';
|
||||
import {loadSponsorsFromString, makeIconSets, parse} from '../lib/sponsors';
|
||||
import {Sponsor} from '../lib/sponsors.interfaces';
|
||||
|
||||
import {resolvePathFromTestRoot, should} from './utils';
|
||||
|
||||
@@ -48,22 +50,22 @@ describe('Sponsors', () => {
|
||||
should.equal(obj.statsId, undefined);
|
||||
});
|
||||
it('should make descriptions always one-sized arrays', () => {
|
||||
parse({name: 'moo', description: 'desc'}).description.should.deep.eq(['desc']);
|
||||
unwrap(parse({name: 'moo', description: 'desc'}).description).should.deep.eq(['desc']);
|
||||
});
|
||||
it('should pass through descriptions', () => {
|
||||
parse({name: 'moo', description: ['desc1', 'desc2']}).description.should.deep.eq(['desc1', 'desc2']);
|
||||
unwrap(parse({name: 'moo', description: ['desc1', 'desc2']}).description).should.deep.eq(['desc1', 'desc2']);
|
||||
});
|
||||
it('should pass through icons', () => {
|
||||
parse({name: 'bob', icon: 'icon'}).icon.should.eq('icon');
|
||||
unwrap(parse({name: 'bob', icon: 'icon'}).icon).should.eq('icon');
|
||||
});
|
||||
it('should pick icons over images', () => {
|
||||
parse({name: 'bob', img: 'img', icon: 'icon'}).icon.should.eq('icon');
|
||||
unwrap(parse({name: 'bob', img: 'img', icon: 'icon'}).icon).should.eq('icon');
|
||||
});
|
||||
it('should pick icons if not img', () => {
|
||||
parse({name: 'bob', img: 'img'}).icon.should.eq('img');
|
||||
unwrap(parse({name: 'bob', img: 'img'}).icon).should.eq('img');
|
||||
});
|
||||
it('should pick dark icons if specified', () => {
|
||||
parse({name: 'bob', icon: 'icon', icon_dark: 'icon_dark'}).icon_dark.should.eq('icon_dark');
|
||||
unwrap(parse({name: 'bob', icon: 'icon', icon_dark: 'icon_dark'}).icon_dark).should.eq('icon_dark');
|
||||
});
|
||||
it('should handle topIcons', () => {
|
||||
parse({name: 'bob', topIconShowEvery: 2}).topIconShowEvery.should.eq(2);
|
||||
@@ -232,7 +234,7 @@ describe('Our specific sponsor file', () => {
|
||||
const expectedNumIcons = 3;
|
||||
|
||||
const sponsors = loadSponsorsFromString(stringConfig);
|
||||
const picks = [];
|
||||
const picks: Sponsor[][] = [];
|
||||
for (let load = 0; load < numLoads; ++load) {
|
||||
picks.push(sponsors.pickTopIcons());
|
||||
}
|
||||
@@ -31,10 +31,10 @@ describe('Normalizing clientstate', () => {
|
||||
it('Should translate 2 compilers GL layout to clientstate', () => {
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
|
||||
const data = JSON.parse(fs.readFileSync('test/state/twocompilers.json'));
|
||||
const data = JSON.parse(fs.readFileSync('test/state/twocompilers.json', {encoding: 'utf8'}));
|
||||
normalizer.fromGoldenLayout(data);
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/twocompilers.json.normalized'));
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/twocompilers.json.normalized', {encoding: 'utf8'}));
|
||||
|
||||
// note: this trick is to get rid of undefined parameters
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
@@ -45,11 +45,13 @@ describe('Normalizing clientstate', () => {
|
||||
it('Should recognize everything and kitchensink as well', () => {
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
|
||||
const data = JSON.parse(fs.readFileSync('test/state/andthekitchensink.json'));
|
||||
const data = JSON.parse(fs.readFileSync('test/state/andthekitchensink.json', {encoding: 'utf8'}));
|
||||
|
||||
normalizer.fromGoldenLayout(data);
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/andthekitchensink.json.normalized'));
|
||||
const resultdata = JSON.parse(
|
||||
fs.readFileSync('test/state/andthekitchensink.json.normalized', {encoding: 'utf8'}),
|
||||
);
|
||||
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
|
||||
@@ -59,11 +61,13 @@ describe('Normalizing clientstate', () => {
|
||||
it('Should support conformanceview', () => {
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
|
||||
const data = JSON.parse(fs.readFileSync('test/state/conformanceview.json'));
|
||||
const data = JSON.parse(fs.readFileSync('test/state/conformanceview.json', {encoding: 'utf8'}));
|
||||
|
||||
normalizer.fromGoldenLayout(data);
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/conformanceview.json.normalized'));
|
||||
const resultdata = JSON.parse(
|
||||
fs.readFileSync('test/state/conformanceview.json.normalized', {encoding: 'utf8'}),
|
||||
);
|
||||
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
|
||||
@@ -73,11 +77,11 @@ describe('Normalizing clientstate', () => {
|
||||
it('Should support executors', () => {
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
|
||||
const data = JSON.parse(fs.readFileSync('test/state/executor.json'));
|
||||
const data = JSON.parse(fs.readFileSync('test/state/executor.json', {encoding: 'utf8'}));
|
||||
|
||||
normalizer.fromGoldenLayout(data);
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/executor.json.normalized'));
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/executor.json.normalized', {encoding: 'utf8'}));
|
||||
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
|
||||
@@ -87,11 +91,11 @@ describe('Normalizing clientstate', () => {
|
||||
it('Should support newer features', () => {
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
|
||||
const data = JSON.parse(fs.readFileSync('test/state/executorwrap.json'));
|
||||
const data = JSON.parse(fs.readFileSync('test/state/executorwrap.json', {encoding: 'utf8'}));
|
||||
|
||||
normalizer.fromGoldenLayout(data);
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/executorwrap.json.normalized'));
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/executorwrap.json.normalized', {encoding: 'utf8'}));
|
||||
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
|
||||
@@ -100,10 +104,12 @@ describe('Normalizing clientstate', () => {
|
||||
|
||||
it('Allow output without editor id', () => {
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
const data = JSON.parse(fs.readFileSync('test/state/output-editor-id.json'));
|
||||
const data = JSON.parse(fs.readFileSync('test/state/output-editor-id.json', {encoding: 'utf8'}));
|
||||
normalizer.fromGoldenLayout(data);
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/output-editor-id.normalized.json'));
|
||||
const resultdata = JSON.parse(
|
||||
fs.readFileSync('test/state/output-editor-id.normalized.json', {encoding: 'utf8'}),
|
||||
);
|
||||
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
|
||||
@@ -145,7 +151,7 @@ describe('ClientState parsing', () => {
|
||||
});
|
||||
|
||||
it('Should not contain id-less compilers', () => {
|
||||
const jsonStr = fs.readFileSync('test/state/bug-2231.json');
|
||||
const jsonStr = fs.readFileSync('test/state/bug-2231.json', {encoding: 'utf8'});
|
||||
const state = new ClientState(JSON.parse(jsonStr));
|
||||
state.sessions[0].compilers.length.should.equal(1);
|
||||
});
|
||||
@@ -153,7 +159,7 @@ describe('ClientState parsing', () => {
|
||||
|
||||
describe('Trees', () => {
|
||||
it('ClientState to GL', () => {
|
||||
const jsonStr = fs.readFileSync('test/state/tree.json');
|
||||
const jsonStr = fs.readFileSync('test/state/tree.json', {encoding: 'utf8'});
|
||||
const state = new ClientState(JSON.parse(jsonStr));
|
||||
state.trees.length.should.equal(1);
|
||||
|
||||
@@ -162,12 +168,12 @@ describe('Trees', () => {
|
||||
|
||||
const golden = JSON.parse(JSON.stringify(gl.golden));
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/tree.goldenified.json'));
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/tree.goldenified.json', {encoding: 'utf8'}));
|
||||
golden.should.deep.equal(resultdata);
|
||||
});
|
||||
|
||||
it('GL to ClientState', () => {
|
||||
const jsonStr = fs.readFileSync('test/state/tree-gl.json');
|
||||
const jsonStr = fs.readFileSync('test/state/tree-gl.json', {encoding: 'utf8'});
|
||||
const gl = JSON.parse(jsonStr);
|
||||
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
@@ -175,13 +181,13 @@ describe('Trees', () => {
|
||||
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/tree.normalized.json'));
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/tree.normalized.json', {encoding: 'utf8'}));
|
||||
|
||||
normalized.should.deep.equal(resultdata);
|
||||
});
|
||||
|
||||
it('GL to ClientState with correct output pane', () => {
|
||||
const jsonStr = fs.readFileSync('test/state/tree-gl-outputpane.json');
|
||||
const jsonStr = fs.readFileSync('test/state/tree-gl-outputpane.json', {encoding: 'utf8'});
|
||||
const gl = JSON.parse(jsonStr);
|
||||
|
||||
const normalizer = new ClientStateNormalizer();
|
||||
@@ -189,13 +195,15 @@ describe('Trees', () => {
|
||||
|
||||
const normalized = JSON.parse(JSON.stringify(normalizer.normalized));
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/tree-gl-outputpane.normalized.json'));
|
||||
const resultdata = JSON.parse(
|
||||
fs.readFileSync('test/state/tree-gl-outputpane.normalized.json', {encoding: 'utf8'}),
|
||||
);
|
||||
|
||||
normalized.should.deep.equal(resultdata);
|
||||
});
|
||||
|
||||
it('ClientState to Mobile GL', () => {
|
||||
const jsonStr = fs.readFileSync('test/state/tree-mobile.json');
|
||||
const jsonStr = fs.readFileSync('test/state/tree-mobile.json', {encoding: 'utf8'});
|
||||
const state = new ClientState(JSON.parse(jsonStr));
|
||||
state.trees.length.should.equal(1);
|
||||
|
||||
@@ -205,7 +213,7 @@ describe('Trees', () => {
|
||||
const golden = JSON.parse(JSON.stringify(slides));
|
||||
//fs.writeFileSync('test/state/tree-mobile.goldenified.json', JSON.stringify(golden));
|
||||
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/tree-mobile.goldenified.json'));
|
||||
const resultdata = JSON.parse(fs.readFileSync('test/state/tree-mobile.goldenified.json', {encoding: 'utf8'}));
|
||||
golden.should.deep.equal(resultdata);
|
||||
});
|
||||
});
|
||||
@@ -22,12 +22,14 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import express from 'express';
|
||||
|
||||
import {RouteAPI} from '../lib/handlers/route-api';
|
||||
|
||||
import {fs} from './utils';
|
||||
|
||||
describe('Basic unfurls', () => {
|
||||
const router = null;
|
||||
const router = null as any as express.Router;
|
||||
let config;
|
||||
let routeApi;
|
||||
|
||||
@@ -52,7 +54,7 @@ describe('Basic unfurls', () => {
|
||||
});
|
||||
|
||||
it('Too many editors to meta', async () => {
|
||||
const prom = new Promise((resolve, reject) => {
|
||||
const prom = new Promise<any>((resolve, reject) => {
|
||||
config.renderGoldenLayout = (config, metadata) => {
|
||||
resolve({metadata});
|
||||
};
|
||||
@@ -81,7 +83,7 @@ describe('Basic unfurls', () => {
|
||||
});
|
||||
|
||||
it('Just one editor', async () => {
|
||||
const prom = new Promise((resolve, reject) => {
|
||||
const prom = new Promise<any>((resolve, reject) => {
|
||||
config.renderGoldenLayout = (config, metadata) => {
|
||||
resolve({metadata});
|
||||
};
|
||||
@@ -111,7 +113,7 @@ describe('Basic unfurls', () => {
|
||||
});
|
||||
|
||||
it('Tree things', async () => {
|
||||
const prom = new Promise((resolve, reject) => {
|
||||
const prom = new Promise<any>((resolve, reject) => {
|
||||
config.renderGoldenLayout = (config, metadata) => {
|
||||
resolve({metadata});
|
||||
};
|
||||
@@ -25,6 +25,8 @@
|
||||
import path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
|
||||
import winston from 'winston';
|
||||
|
||||
import {logger, makeLogStream} from '../lib/logger';
|
||||
import * as utils from '../lib/utils';
|
||||
|
||||
@@ -373,8 +375,8 @@ describe('Anonymizes all kind of IPs', () => {
|
||||
|
||||
describe('Logger functionality', () => {
|
||||
it('correctly logs streams split over lines', () => {
|
||||
const logs = [];
|
||||
const fakeLog = {log: (level, msg) => logs.push({level, msg})};
|
||||
const logs: {level: string; msg: string}[] = [];
|
||||
const fakeLog = {log: (level: string, msg: string) => logs.push({level, msg})} as any as winston.Logger;
|
||||
const infoStream = makeLogStream('info', fakeLog);
|
||||
infoStream.write('first\n');
|
||||
infoStream.write('part');
|
||||
@@ -391,8 +393,8 @@ describe('Logger functionality', () => {
|
||||
]);
|
||||
});
|
||||
it('correctly logs streams to the right destination', () => {
|
||||
const logs = [];
|
||||
const fakeLog = {log: (level, msg) => logs.push({level, msg})};
|
||||
const logs: {level: string; msg: string}[] = [];
|
||||
const fakeLog = {log: (level: string, msg: string) => logs.push({level, msg})} as any as winston.Logger;
|
||||
const infoStream = makeLogStream('warn', fakeLog);
|
||||
infoStream.write('ooh\n');
|
||||
logs.should.deep.equal([
|
||||
@@ -26,17 +26,21 @@ import child_process from 'child_process';
|
||||
|
||||
import {WineVcCompiler} from '../lib/compilers/wine-vc';
|
||||
import {WslVcCompiler} from '../lib/compilers/wsl-vc';
|
||||
import {LanguageKey} from '../types/languages.interfaces';
|
||||
|
||||
import {makeCompilationEnvironment} from './utils';
|
||||
import {makeCompilationEnvironment, makeFakeCompilerInfo} from './utils';
|
||||
|
||||
const languages = {
|
||||
'c++': {id: 'c++'},
|
||||
};
|
||||
|
||||
const info = {
|
||||
lang: languages['c++'].id,
|
||||
exe: null,
|
||||
remote: true,
|
||||
lang: languages['c++'].id as LanguageKey,
|
||||
exe: '/dev/null',
|
||||
remote: {
|
||||
target: 'foo',
|
||||
path: 'bar',
|
||||
},
|
||||
};
|
||||
|
||||
describe('Paths', () => {
|
||||
@@ -47,14 +51,14 @@ describe('Paths', () => {
|
||||
});
|
||||
|
||||
it('Linux -> Wine path', () => {
|
||||
const compiler = new WineVcCompiler(info, env);
|
||||
const compiler = new WineVcCompiler(makeFakeCompilerInfo(info), env);
|
||||
compiler.filename('/tmp/123456/output.s').should.equal('Z:/tmp/123456/output.s');
|
||||
});
|
||||
|
||||
it('Linux -> Windows path', function () {
|
||||
process.env.winTmp = '/mnt/c/tmp';
|
||||
|
||||
const compiler = new WslVcCompiler(info, env);
|
||||
const compiler = new WslVcCompiler(makeFakeCompilerInfo(info), env);
|
||||
compiler.filename('/mnt/c/tmp/123456/output.s').should.equal('c:/tmp/123456/output.s');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user