-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test (#508): Added basic tests for @kipper/config
To be extended!
- Loading branch information
1 parent
b207bc3
commit c6cdca1
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
{ | ||
"outDir": "dist", | ||
"srcDir": "test/kipper-files", | ||
"compiler": { | ||
"version": "*", | ||
"target": "ts" | ||
}, | ||
"files": [ | ||
"src/index.kip" | ||
"test/kipper-files/main.kip" | ||
], | ||
"resources": [ | ||
"my-image.png" | ||
"img/icon.png" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
import { getFileName } from "./utils/utils"; | ||
import { assert } from "chai"; | ||
import { KipperConfigFile, KipperConfigInterpreter, version as kipConfigVersion } from "@kipper/config"; | ||
import * as semver from "semver"; | ||
|
||
const basicKipConfig = getFileName("kip-config.basic.json"); | ||
|
||
describe("KipperConfigInterpreter", () => { | ||
describe("loadConfig", () => { | ||
describe("no extends", () => { | ||
const interpreter = new KipperConfigInterpreter(); | ||
|
||
it("should load a basic config", async () => { | ||
const kipperConfigFile = await KipperConfigFile.fromFile(basicKipConfig, "utf8"); | ||
const config = await interpreter.loadConfig(kipperConfigFile); | ||
|
||
const pwd = process.cwd(); | ||
assert.deepEqual(config.raw, { | ||
basePath: pwd, | ||
srcDir: `${pwd}/test/kipper-files`, | ||
outDir: `${pwd}/dist`, | ||
compiler: { | ||
version: semver.parse(semver.clean(kipConfigVersion))!, | ||
target: "ts" | ||
}, | ||
files: [ | ||
{ src: `${pwd}/test/kipper-files/main.kip`, outDir: `${pwd}/dist` } | ||
], | ||
resources: [ | ||
{ src: `${pwd}/img/icon.png`, out: `${pwd}/dist/img/icon.png` } | ||
] | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
import { FileNotFoundError, KipperConfigFile } from "@kipper/config"; | ||
import { getFileName } from "./utils/utils"; | ||
import { assert } from "chai"; | ||
import * as path from "path"; | ||
import * as fs from "node:fs/promises"; | ||
|
||
const basicKipConfig = getFileName("kip-config.basic.json"); | ||
|
||
describe("KipperConfigFile", () => { | ||
const encoding = "utf8"; | ||
|
||
describe("fromString", () => { | ||
it("should return a KipperConfigFile instance", () => { | ||
const kipConfig = KipperConfigFile.fromString("{}", encoding); | ||
assert.instanceOf(kipConfig, KipperConfigFile); | ||
assert.strictEqual(kipConfig.content, "{}"); | ||
assert.deepEqual(kipConfig.parsedJSON, {}); | ||
assert.strictEqual(kipConfig.fileName, "<string>"); | ||
assert.strictEqual(kipConfig.encoding, encoding); | ||
}); | ||
}); | ||
|
||
describe("fromFile", () => { | ||
it("should return a KipperConfigFile instance", async () => { | ||
// First get the file content to check what we are expecting | ||
const fileContent = await fs.readFile(basicKipConfig, { encoding }); | ||
|
||
const kipConfig = await KipperConfigFile.fromFile(basicKipConfig, encoding); | ||
assert.instanceOf(kipConfig, KipperConfigFile); | ||
assert.strictEqual(kipConfig.content, fileContent); | ||
assert.deepEqual(kipConfig.parsedJSON, JSON.parse(fileContent)); | ||
assert.strictEqual(kipConfig.fileName, path.basename(basicKipConfig)); | ||
assert.strictEqual(kipConfig.encoding, encoding); | ||
}); | ||
|
||
it("should throw an error if the file does not exist", async () => { | ||
try { | ||
await KipperConfigFile.fromFile(getFileName("does-not-exist.json"), encoding); | ||
assert.fail("Expected an error to be thrown"); | ||
} catch (error) { | ||
assert.instanceOf(error, FileNotFoundError); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as path from "path"; | ||
|
||
export function getFileName(pathString: string): string { | ||
return path.resolve(`${__dirname}/../../../config-files/${pathString}`); | ||
} |