mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 01:22:54 +00:00
feat: tests
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {LightweightFile} from '../../src/easy-ast/types/lightweight-project.js';
|
||||
import {LightweightFile} from '../src/index.js';
|
||||
|
||||
export interface EasyAstSpecType {
|
||||
testName: string;
|
||||
|
||||
48
packages/easy-ast/test/index.spec.ts
Normal file
48
packages/easy-ast/test/index.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {lightweightProjectFromPath} from '../src/index.js';
|
||||
import {expect} from 'chai';
|
||||
import {expandPathToFilesSync, toUnixPath} from '../src/util.js';
|
||||
import type {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
|
||||
const projectPath = './test/project';
|
||||
|
||||
const tests = await Promise.all(
|
||||
expandPathToFilesSync(projectPath, file => file.endsWith('ast-test.ts')).map(async it => ({
|
||||
path: toUnixPath(it),
|
||||
config: await import(`file://${it}`).then(it => it.testConfig as EasyAstSpecType),
|
||||
})),
|
||||
);
|
||||
|
||||
describe('Easy AST', async function () {
|
||||
it('should build the project', function () {
|
||||
const project = lightweightProjectFromPath(projectPath, true);
|
||||
expect(Object.keys(project).length).to.equal(tests.length);
|
||||
});
|
||||
|
||||
const project = lightweightProjectFromPath(projectPath, true);
|
||||
|
||||
for (const {path, config} of tests) {
|
||||
it(config.testName, function () {
|
||||
const projectAtPath = project[path];
|
||||
expect(projectAtPath).not.to.be.undefined;
|
||||
for (const key in projectAtPath) {
|
||||
if (key.startsWith('$')) delete projectAtPath[key];
|
||||
}
|
||||
|
||||
expect(projectAtPath).to.be.deep.equal(config.expected);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {expandPathToFilesSync, toUnixPath} from '../src/util.js';
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {lightweightProjectFromPath} from '../src/easy-ast.js';
|
||||
import {expect} from 'chai';
|
||||
|
||||
describe('Easy AST', async () => {
|
||||
const project = lightweightProjectFromPath('./test/easy-ast', true);
|
||||
for (const file of expandPathToFilesSync('./test/easy-ast', file => file.endsWith('ast-test.ts'))) {
|
||||
try {
|
||||
const test = (await import(file))['testConfig'] as EasyAstSpecType;
|
||||
|
||||
it(test.testName, () => {
|
||||
expect(omitBy(project[toUnixPath(file)], (_value, key) => key.startsWith('$'))).to.be.deep.equal(
|
||||
test.expected,
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -13,11 +13,13 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
// @ts-expect-error unused type
|
||||
type TestTypeAlias = number | string;
|
||||
|
||||
// @ts-expect-error unused type
|
||||
enum TestEnum {
|
||||
Foo,
|
||||
Bar,
|
||||
@@ -13,14 +13,18 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
interface Random {}
|
||||
|
||||
// @ts-expect-error unused type
|
||||
type TestArrayGeneric = Array<string>;
|
||||
// @ts-expect-error unused type
|
||||
type TestArrayLiteral = number[];
|
||||
// @ts-expect-error unused type
|
||||
type TestArrayReferenceGeneric = Array<Random>;
|
||||
// @ts-expect-error unused type
|
||||
type TestArrayReferenceLiteral = Random[];
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
@@ -13,13 +13,15 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
// @ts-expect-error unused type
|
||||
interface TestInterface {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
// @ts-expect-error unused type
|
||||
class TestClass {
|
||||
bar: string = 'test';
|
||||
}
|
||||
@@ -13,8 +13,8 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
/**
|
||||
* Class comment
|
||||
@@ -25,6 +25,7 @@ import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-de
|
||||
*
|
||||
* @classTag classParameter1 classParameter2
|
||||
*/
|
||||
// @ts-expect-error unused type
|
||||
interface TestInterface {
|
||||
/**
|
||||
* Property comment
|
||||
@@ -47,6 +48,7 @@ interface TestInterface {
|
||||
*
|
||||
* @classTag classParameter1 classParameter2
|
||||
*/
|
||||
// @ts-expect-error unused type
|
||||
class TestClass {
|
||||
/**
|
||||
* Property comment
|
||||
@@ -69,6 +71,7 @@ class TestClass {
|
||||
*
|
||||
* @enumTag enumParameter1
|
||||
*/
|
||||
// @ts-expect-error unused type
|
||||
enum TestAlias {}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
@@ -13,13 +13,14 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
interface Test1<T = number> {
|
||||
foo: T;
|
||||
}
|
||||
|
||||
// @ts-expect-error unused type
|
||||
interface Test2 {
|
||||
bar: Test1;
|
||||
}
|
||||
@@ -13,14 +13,16 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
// @ts-expect-error unused type
|
||||
enum TestAuto {
|
||||
Foo,
|
||||
Bar,
|
||||
}
|
||||
|
||||
// @ts-expect-error unused type
|
||||
enum TestSpecified {
|
||||
YES = 'yes',
|
||||
NO = 'no',
|
||||
@@ -13,11 +13,12 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
interface $Random {}
|
||||
|
||||
// @ts-expect-error unused type
|
||||
interface Generics {
|
||||
baz: Foo<number, $Random>;
|
||||
}
|
||||
@@ -13,15 +13,17 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
interface $Random {}
|
||||
|
||||
// @ts-expect-error unused
|
||||
interface IndexSignatureObject {
|
||||
[key: string]: $Random;
|
||||
}
|
||||
|
||||
// @ts-expect-error unused
|
||||
interface IndexSignaturePrimitive {
|
||||
[key: string]: number;
|
||||
}
|
||||
@@ -13,8 +13,8 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
interface $BaseInterface<T> {
|
||||
foo: T;
|
||||
@@ -26,6 +26,7 @@ interface $BaseInterface2 {
|
||||
|
||||
class $BaseClass {}
|
||||
|
||||
// @ts-expect-error unused
|
||||
class InheritingClass extends $BaseClass implements $BaseInterface<number>, $BaseInterface2 {
|
||||
bar: string = '';
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
// @ts-expect-error unused
|
||||
interface NestedObject {
|
||||
nested: {
|
||||
deeplyNested: {
|
||||
@@ -13,9 +13,10 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
// @ts-expect-error unused
|
||||
interface Test {
|
||||
number_type: number;
|
||||
string_type: string;
|
||||
@@ -13,9 +13,10 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind.js';
|
||||
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
|
||||
import {LightweightDefinitionKind} from '../../src/index.js';
|
||||
|
||||
// @ts-expect-error unused
|
||||
interface Foo<T extends Bar<string>> {
|
||||
bar: T;
|
||||
}
|
||||
Reference in New Issue
Block a user