diff --git a/cli2/dependencies.test.ts b/cli2/dependencies.test.ts index e2af0ff30..9350e96e1 100644 --- a/cli2/dependencies.test.ts +++ b/cli2/dependencies.test.ts @@ -1,121 +1,124 @@ - -import * as dep from './dependencies'; +import * as dep from "./dependencies"; import { z, ZodError } from "zod"; -import * as path from 'path' +import * as path from "path"; import { decode, labelToName } from "whatwg-encoding"; -describe('the dependencies module', () => { - - test("should declare loadAllDependencies", async () => { - expect(dep.loadAllDependencies).toBeDefined - }) - - test("should declare configuration types", async () => { - expect(dep.DataUrl).toBeDefined - expect(dep.FileUrl).toBeDefined - expect(dep.LocalFile).toBeDefined - }) - - describe("The LocalFile configuration type", () => { - test("should fail if can't find the file.", () => { - try { - dep.LocalFile.parse({ - projectDir: __dirname, - sanitized: "./shouldFail.ir" - }); - } catch (error) { - expect(error instanceof ZodError).toBeTruthy; - let issues = (error as ZodError).issues; - let expectedIssue = { - "code": "custom", - "message": "File not found ./shouldFail.ir", - }; - expect(issues[0].message).toBe(expectedIssue.message); - expect(issues[0].code).toBe(expectedIssue.code); - - } - }); - test("should support local file.", () => { - let fileName = 'dependencies.ts' - let expectedFile = path.join(__dirname, fileName); - - let expectedUrl = new URL(`file://${expectedFile}`); - - let { success: urlSuccess, data: urlData } = dep.LocalFile.safeParse({ - projectDir: __dirname, - sanitized: `./${fileName}` - }); - expect({ success: urlSuccess, data: urlData }).toStrictEqual({ success: true, data: expectedUrl }); - }); - test("should support local files on an above folder", () => { - let fileName = 'gulpfile.js' - let expectedFile = path.join(__dirname, '..', fileName); - - let expectedUrl = new URL(`file://${expectedFile}`); - let { success: urlSuccess, data: urlData } = dep.LocalFile.safeParse({ - projectDir: __dirname, - sanitized: `../${fileName}` - }); - expect({ success: urlSuccess, data: urlData }).toStrictEqual({ success: true, data: expectedUrl }); - }); - test("should support local files on a sibling folder", () => { - let fileName = 'morphir.js' - let expectedFile = path.resolve(__dirname, "..", "cli", fileName); - - let expectedUrl = new URL(`file://${expectedFile}`); - let { success: urlSuccess, data: urlData } = dep.LocalFile.safeParse({ - projectDir: __dirname, - sanitized: `../cli/${fileName}` - }); - expect({ success: urlSuccess, data: urlData }).toStrictEqual({ success: true, data: expectedUrl }); +describe("the dependencies module", () => { + test("should declare loadAllDependencies", async () => { + expect(dep.loadAllDependencies).toBeDefined; + }); + + test("should declare configuration types", async () => { + expect(dep.DataUrl).toBeDefined; + expect(dep.FileUrl).toBeDefined; + expect(dep.LocalFile).toBeDefined; + }); + + describe("The LocalFile configuration type", () => { + test("should fail if can't find the file.", () => { + try { + dep.LocalFile.parse({ + projectDir: __dirname, + sanitized: "./shouldFail.ir", }); + } catch (error) { + expect(error instanceof ZodError).toBeTruthy; + let issues = (error as ZodError).issues; + let expectedIssue = { + code: "custom", + message: "File not found ./shouldFail.ir", + }; + expect(issues[0].message).toBe(expectedIssue.message); + expect(issues[0].code).toBe(expectedIssue.code); + } }); - describe("The Url configuration type", () => { - test("should support http.", () => { - let url = "http://www.google.com/" - let { success, data: fileData } = dep.Url.safeParse(url); - expect(success).toBeTruthy() - expect(fileData).toStrictEqual(new URL(url)); - }); - test("should support https.", () => { - let url = "https://www.google.com/" - let { success, data: fileData } = dep.Url.safeParse(url); - expect(success).toBeTruthy() - expect(fileData).toStrictEqual(new URL(url)); - }); - test("should support ftp.", () => { - let url = "ftp://www.google.com/" - let { success, data: fileData } = dep.Url.safeParse(url); - expect(success).toBeTruthy() - expect(fileData).toStrictEqual(new URL(url)); - }); - test("should NOT support S3.", () => { - let url = "s3://www.aws.com/mybucket" - let { success, data: fileData } = dep.Url.safeParse(url); - expect(success).toBeFalsy() - expect(fileData).toBeUndefined - }); + test("should support local file.", () => { + let fileName = "dependencies.ts"; + let expectedFile = path.join(__dirname, fileName); + + let expectedUrl = new URL(`file://${expectedFile}`); + + let { success: urlSuccess, data: urlData } = dep.LocalFile.safeParse({ + projectDir: __dirname, + sanitized: `./${fileName}`, + }); + expect({ success: urlSuccess, data: urlData }).toStrictEqual({ + success: true, + data: expectedUrl, + }); }); - - describe("The DataURL type", ()=>{ - - test("should support encoded json.", () => { - - let obj = {hello: "world"} - let content = encodeURIComponent(JSON.stringify(obj)) - let { success, data: parseResult } = dep.DataUrl.safeParse("data:text/html,"+content); - expect(success).toBeTruthy() - - const encodingName = labelToName(parseResult.mimeType.parameters.get("charset") || "utf-8") || "UTF-8"; - const bodyDecoded = decode(parseResult.body, encodingName); - - - expect(bodyDecoded).toStrictEqual(JSON.stringify(obj)); - - }); - - }) - - - -}) + test("should support local files on an above folder", () => { + let fileName = "gulpfile.mjs"; + let expectedFile = path.join(__dirname, "..", fileName); + + let expectedUrl = new URL(`file://${expectedFile}`); + let { success: urlSuccess, data: urlData } = dep.LocalFile.safeParse({ + projectDir: __dirname, + sanitized: `../${fileName}`, + }); + expect({ success: urlSuccess, data: urlData }).toStrictEqual({ + success: true, + data: expectedUrl, + }); + }); + test("should support local files on a sibling folder", () => { + let fileName = "morphir.js"; + let expectedFile = path.resolve(__dirname, "..", "cli", fileName); + + let expectedUrl = new URL(`file://${expectedFile}`); + let { success: urlSuccess, data: urlData } = dep.LocalFile.safeParse({ + projectDir: __dirname, + sanitized: `../cli/${fileName}`, + }); + expect({ success: urlSuccess, data: urlData }).toStrictEqual({ + success: true, + data: expectedUrl, + }); + }); + }); + describe("The Url configuration type", () => { + test("should support http.", () => { + let url = "http://www.google.com/"; + let { success, data: fileData } = dep.Url.safeParse(url); + expect(success).toBeTruthy(); + expect(fileData).toStrictEqual(new URL(url)); + }); + test("should support https.", () => { + let url = "https://www.google.com/"; + let { success, data: fileData } = dep.Url.safeParse(url); + expect(success).toBeTruthy(); + expect(fileData).toStrictEqual(new URL(url)); + }); + test("should support ftp.", () => { + let url = "ftp://www.google.com/"; + let { success, data: fileData } = dep.Url.safeParse(url); + expect(success).toBeTruthy(); + expect(fileData).toStrictEqual(new URL(url)); + }); + test("should NOT support S3.", () => { + let url = "s3://www.aws.com/mybucket"; + let { success, data: fileData } = dep.Url.safeParse(url); + expect(success).toBeFalsy(); + expect(fileData).toBeUndefined; + }); + }); + + describe("The DataURL type", () => { + test("should support encoded json.", () => { + let obj = { hello: "world" }; + let content = encodeURIComponent(JSON.stringify(obj)); + let { success, data: parseResult } = dep.DataUrl.safeParse( + "data:text/html," + content + ); + expect(success).toBeTruthy(); + + const encodingName = + labelToName( + parseResult.mimeType.parameters.get("charset") || "utf-8" + ) || "UTF-8"; + const bodyDecoded = decode(parseResult.body, encodingName); + + expect(bodyDecoded).toStrictEqual(JSON.stringify(obj)); + }); + }); +}); diff --git a/gulpfile.js b/gulpfile.mjs similarity index 100% rename from gulpfile.js rename to gulpfile.mjs diff --git a/package.json b/package.json index ebe524d10..2c80c3855 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "morphir-elm", "version": "2.89.0", "description": "Elm bindings for Morphir", - "type": "module", + "type": "commonjs", "types": "lib/dist/main.d.ts", "main": "lib/dist/main.js", "module": "es6",