From 46ab9e223fe7ac9f990048b27748209227e5d4a2 Mon Sep 17 00:00:00 2001 From: InversionSpaces Date: Wed, 6 Dec 2023 11:33:35 +0000 Subject: [PATCH] Add test --- .../__test__/data/transitive-deps/A-0.1.0.tgz | Bin 0 -> 907 bytes .../__test__/data/transitive-deps/B-0.1.0.tgz | Bin 0 -> 886 bytes .../__test__/data/transitive-deps/C-0.1.0.tgz | Bin 0 -> 1438 bytes .../__test__/data/transitive-deps/C-0.2.0.tgz | Bin 0 -> 931 bytes .../data/transitive-deps/project/main.aqua | 12 +++++++ .../data/transitive-deps/project/package.json | 8 +++++ api/api-npm/__test__/imports.spec.ts | 34 ++++++++++++++++++ api/api-npm/imports.d.ts | 2 +- api/api-npm/index.d.ts | 2 -- api/api-npm/jest.config.cjs | 16 +++++++++ api/api-npm/package.json | 11 +++++- api/api-npm/tsconfig.json | 21 +++++++++++ 12 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 api/api-npm/__test__/data/transitive-deps/A-0.1.0.tgz create mode 100644 api/api-npm/__test__/data/transitive-deps/B-0.1.0.tgz create mode 100644 api/api-npm/__test__/data/transitive-deps/C-0.1.0.tgz create mode 100644 api/api-npm/__test__/data/transitive-deps/C-0.2.0.tgz create mode 100644 api/api-npm/__test__/data/transitive-deps/project/main.aqua create mode 100644 api/api-npm/__test__/data/transitive-deps/project/package.json create mode 100644 api/api-npm/__test__/imports.spec.ts create mode 100644 api/api-npm/jest.config.cjs create mode 100644 api/api-npm/tsconfig.json diff --git a/api/api-npm/__test__/data/transitive-deps/A-0.1.0.tgz b/api/api-npm/__test__/data/transitive-deps/A-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..8613afeda1b946c0322a4b9b84d055f82b364c3f GIT binary patch literal 907 zcmV;619bc!iwFP!00002|0_sL&Q45E)pyiOEG$iApb0QAFfcPQQNSh+0)|HB3Jk`k zW(J0aW@ZLJbq0n8#)gJKnt=|Ww74X(2p}n5?6-hNgn9okDR*QD$Dc6_)}K*yt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15v{#S`{O1Gc)(kEo}tg{$7==~n+OSQonE=QeKJJ+-{+xsN={`7^s<*Y2w7 z!{P^L{0`qfchZ^(+`A@x$$TF(eb2K^!T+86{La-CKTrR0_ENq7)jav%#s3m^wEz2- z9<2T2o6V1R^KN|2JbH-J=imNci_9YPy}sI-|Ne2DUEgfl@%Q`}tUncc5V-`F4@X$N$BdE4M$bm#lE}ZU{8say#h3%J3qh`#yufXsJ00M!_f;1w$VI M0HF44eE<>w0PgtJng9R* literal 0 HcmV?d00001 diff --git a/api/api-npm/__test__/data/transitive-deps/C-0.1.0.tgz b/api/api-npm/__test__/data/transitive-deps/C-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..a4bd55ec742a717361fc11fca5db37ea735b9785 GIT binary patch literal 1438 zcmV;P1!4LhiwFP!00002|0_sL&Q45E)pyoQEG$iApb0QAFfcPQQNSh+0)_@g3Jk`k zW(J0aW@ZLJbwCkgFwH;*P+DA)SOjzm6+8(93UGRe08p$eICF8ORutqHl_->@78Pga z=K%%MO7oK8Tn$YHT|0&1lA_GKbSo|eAh6L@P%_Xn)H6_G7zINZ6hQMol-A2C&d;NB z{x>i+M$i9-rY58LpDv&poST*M5_40PtQ3@-m2@Bi(3}qvgJg5A+R@B1jPt*itn(j+|R%>nw2Te|3(9n{|(Jdu;hQE(fm*6{IBidbI#Al|7!U) zZyg=qlm(oSvN`a88Xr>|n;RF;v1Ms&ZEb03Y!0Okg2@JF9oPe+VkSkflyHgKaI$a} zRCO=}tkJe8E?gQW@9#+0REqUq0`GqPUt`aJ1j46iS1taa<7NsG?xDbdzrRoHMb zG{ESB@g?JcBneh$2@!|S_EWB%);f27aq&NM15>y2|J#8|np29`-MV)XF~n+abR9Ked9D!p`p4=5l4@vOk;lgdR^a zTs!~ro}VhMU#9v0meibPdV7PB`Pb%x_G8MNyO(dOy(ZHgBQnog_r~9vOI<(ND;MQe z+symE^6LFl4{~02=hjT>TL0+KbklQYx3;Bmm*2ltd|E#Jqg~1w&u?9^hm4j_b9OPh z+idy&!Rp@s^2=Aa@1OH?_x;bO_x`GM|MvHO%tzJo$dEZ5`N>h8hTfl^-?h}%(XP*3 zHRJoA_bwl0r%nAWS>d+X=;+V;83~{E?_`|zCqKmo=*ijtx7ya6`}y-nyzc&IYZpJB zy{SPs$c$Ys;Bj(Ra`EFwmfLiC*RIvo?LE8jilf2J2WyzC9YW45;g}|*7bxu~wytRv zUt5FeEwQ7m-iKZ0b@*SMu_?sIbrIMXT<#5U;FF3QlxU@ky}lrv;Ew^w?*AtUT=Nm`@iL38-i}!l)W9Z zE+^(&`sH~S9(%TBKaaonIe6*U(M&l3w1s-i@$&J-FiJ`SF+2q z$k+FNL>I4otzP|f(Vnc?mG{Hr_SV00JoozDomrl-ujOTDesX>PTU_^U-~XRq?!`}icmLnL{+}zN zV!Z literal 0 HcmV?d00001 diff --git a/api/api-npm/__test__/data/transitive-deps/C-0.2.0.tgz b/api/api-npm/__test__/data/transitive-deps/C-0.2.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..ab26bea72d40ff1efa7827d4e4539816c6835bac GIT binary patch literal 931 zcmV;U16=$ciwFP!00002|0_sL&Q45E)pyoQEG$iApb0QAFfcPQQNSh+0)_@g3Jk`k zW(J0aW@ZLJbwCkgFwH;*P+DA)SOjzm6+8(93UGRe08p$eICF8ORutqHl_->@78Pga z=K%%MO7oK8Tn$YHT|0&1lA_GKbSo|eAh6L@P%_Xn(lbzE7zINZ6hQMol-A2C&d;NB z{x>i+M$i9-rY58LpDv&poST*M5_40PtQ3@-m2@Bi(3}qvgJg5A+R@B1jPt*g=sIlwg2|F@U-avd@dVSR9}vddeIRXRUs_QDSD z`6^Q)R?WD!MAWgS{Ia}N$6_(9pVPegB!%>rPx~1umNnb3GB@>uaEHbt3A?AVebyX{ zToj%=E!h2h(u(;9d7^H6Jf8Qd)!)kCZ0n0{e3FW<;=-3T&NkY%W(#-U+H=bvXYoE{ z%t`i&UBWV_mP14`-Ge#*;H!=QAE&5CznuBI-}B48`guq8{oh>iC3jg=oQQ8@T8S}B z^5@+-D=aI2ZK{~}{O?5Z9hQ~*8F)ssGR67dXkhZcxdE2^Z)7~0|LL3mwLN^!`T6)? zEx+ciqvM;hfD=+S2Od!4V`^h_Rm! z7OsM-4u*g=+7`uyOT$E-h)>m+vQ$ho{n>Ly)=OTWCq0be^<|BUREr+cLGqKj-T$keV}l>L;P% z;Hhgwrp%dIqQG=v4!=-yO7Xf|7ta{=eBQr#UE{ok^BUtkt3>y{u1|LE`IDcJmSH#R z|4YUvyDblxT>ig(`u8GPBZ0))f_0ltNB4$W*{6Ry#P|NERFFGH2>d{n$t{gZ!j|d+Fa0nOqp}{@=dkZWV&NS=2`3B_*-+S>nD5V zqP%LGdEZxFy?^RK&g<^nnn_*jA03)*dd}?DwlwbY`?rcu%cp;|OF85Dtt_bAIl=|M~RZUzP6P{@#!Is9GKwGN&UyIjYmp`_uEgmfAYn z^|`BNeE;*_<)iGhslO#F+%|vGkYHV$AToi4;Y&fhAA`VX5jF}&!6+aT008xzvkm|h F002>c<-Y&` literal 0 HcmV?d00001 diff --git a/api/api-npm/__test__/data/transitive-deps/project/main.aqua b/api/api-npm/__test__/data/transitive-deps/project/main.aqua new file mode 100644 index 00000000..4e78c16d --- /dev/null +++ b/api/api-npm/__test__/data/transitive-deps/project/main.aqua @@ -0,0 +1,12 @@ +aqua Main + +export versionBC, versionAC + +use "A.aqua" +use "B.aqua" + +func versionAC() -> string: + <- A.versionC() + +func versionBC() -> string: + <- B.versionC() \ No newline at end of file diff --git a/api/api-npm/__test__/data/transitive-deps/project/package.json b/api/api-npm/__test__/data/transitive-deps/project/package.json new file mode 100644 index 00000000..10299fb6 --- /dev/null +++ b/api/api-npm/__test__/data/transitive-deps/project/package.json @@ -0,0 +1,8 @@ +{ + "name": "Project", + "version": "0.1.0", + "dependencies": { + "A": "file:../A-0.1.0.tgz", + "B": "file:../B-0.1.0.tgz" + } +} \ No newline at end of file diff --git a/api/api-npm/__test__/imports.spec.ts b/api/api-npm/__test__/imports.spec.ts new file mode 100644 index 00000000..f008a6f4 --- /dev/null +++ b/api/api-npm/__test__/imports.spec.ts @@ -0,0 +1,34 @@ +import { gatherImportsFromNpm } from "../imports.js"; + +describe("imports", () => { + it("should resolve transitive dependencies", async () => { + const imports = await gatherImportsFromNpm( + "./__test__/data/transitive-deps/project", + ); + + const projectPath = Object.keys(imports).find((p) => p.endsWith("project")); + + expect(projectPath).toBeDefined(); + + const projectImports = imports[projectPath!]; + + expect(projectImports.length).toEqual(2); + + const [dep1Path, dep2Path] = projectImports; + + const dep1Imports = imports[dep1Path]; + const dep2Imports = imports[dep2Path]; + + expect(dep1Imports.length).toEqual(1); + expect(dep2Imports.length).toEqual(1); + + const [dep1Transitive] = dep1Imports; + const [dep2Transitive] = dep2Imports; + + expect(dep1Transitive.endsWith("C")).toBeTruthy(); + expect(dep2Transitive.endsWith("C")).toBeTruthy(); + + // Transitive dependency should be resolved to different paths + expect(dep1Transitive).not.toEqual(dep2Transitive); + }); +}); diff --git a/api/api-npm/imports.d.ts b/api/api-npm/imports.d.ts index 11a6ba93..5f0358ad 100644 --- a/api/api-npm/imports.d.ts +++ b/api/api-npm/imports.d.ts @@ -1,6 +1,6 @@ import Arborist from "@npmcli/arborist"; -import type { Imports } from "./index.d.ts"; +export declare type Imports = Record; /** * Gather imports for aqua compiler from diff --git a/api/api-npm/index.d.ts b/api/api-npm/index.d.ts index f6158d75..d24940a9 100644 --- a/api/api-npm/index.d.ts +++ b/api/api-npm/index.d.ts @@ -21,8 +21,6 @@ export declare class CompilationResult { generatedSources: GeneratedSource[]; } -export type Imports = Record | string[]; - /** Common arguments for all compile functions */ type CommonArgs = { /** Paths to directories, which you want to import .aqua files from. Example: ["./path/to/dir"] */ diff --git a/api/api-npm/jest.config.cjs b/api/api-npm/jest.config.cjs new file mode 100644 index 00000000..43ecfec0 --- /dev/null +++ b/api/api-npm/jest.config.cjs @@ -0,0 +1,16 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + extensionsToTreatAsEsm: [".ts"], + preset: "ts-jest/presets/default-esm", + moduleNameMapper: { + "^(\\.{1,2}/.*)\\.js$": "$1", + }, + transform: { + "^.+\\.tsx?$": [ + "ts-jest", + { + useESM: true, + }, + ], + }, +}; diff --git a/api/api-npm/package.json b/api/api-npm/package.json index c760033d..4669f76b 100644 --- a/api/api-npm/package.json +++ b/api/api-npm/package.json @@ -27,12 +27,21 @@ "url": "https://github.com/fluencelabs/aqua/issues" }, "homepage": "https://github.com/fluencelabs/aqua#readme", + "scripts": { + "test": "NODE_OPTIONS=--experimental-vm-modules npx jest --detectOpenHandles" + }, "optionalDependencies": { "@npmcli/arborist": "7.2.1", "treeverse": "3.0.0" }, "devDependencies": { "@fluencelabs/interfaces": "0.9.0", - "prettier": "3.0.0" + "@types/jest": "29.5.2", + "@types/node": "^20.10.3", + "prettier": "3.0.0", + "jest": "29.5.0", + "ts-jest": "29.1.0", + "ts-node": "10.9.1", + "typescript": "5.1.3" } } diff --git a/api/api-npm/tsconfig.json b/api/api-npm/tsconfig.json new file mode 100644 index 00000000..e76e016c --- /dev/null +++ b/api/api-npm/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "allowJs": true, + "target": "ESNext", + "module": "ESNext", + "lib": ["es2015", "dom"], + "declaration": true, + "outDir": "dist", + "moduleResolution": "nodenext", + "strict": true, + "esModuleInterop": true, + "noImplicitAny": false, + "strictNullChecks": false, + "skipLibCheck": true + }, + "exclude": ["node_modules", "dist", "bundle"], + "include": ["__test__/**/*"], + "ts-node": { + "esm": true + } +}