feat: tests

This commit is contained in:
2023-04-21 12:08:35 +02:00
parent 8cb9285462
commit d8c79256c9
140 changed files with 2100 additions and 2693 deletions

View 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);
});
}
});