-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
92 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
File renamed without changes.
File renamed without changes.
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 @@ | ||
{ | ||
"packages": [ | ||
|
||
] | ||
} |
File renamed without changes.
Empty file.
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,27 +1,76 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { isComposerRoot } from "../src/utils"; | ||
import { describe, expect, test, beforeAll, afterAll } from "@jest/globals"; | ||
import { determineComposerRoot, isComposerRoot, readJsonFile } from "../src/utils"; | ||
import { resolve } from "node:path"; | ||
import mockFs from "mock-fs"; | ||
|
||
describe("utils module", () => { | ||
test("checks projectComposerFile.json to be valid root composer file", () => { | ||
beforeAll(() => { | ||
mockFs({ | ||
"/path/to/fixtures": mockFs.load(resolve(__dirname, "fixtures")) | ||
}); | ||
}) | ||
afterAll(() => { | ||
mockFs.restore(); | ||
}) | ||
|
||
describe("isComposerRoot", () => { | ||
test("checks project composer.json to be valid root composer file", () => { | ||
expect( | ||
isComposerRoot( | ||
resolve(__dirname, "fixtures/projectComposerFile.json"), | ||
), | ||
isComposerRoot("/path/to/fixtures/composerProject/composer.json") | ||
).toBe(true); | ||
}); | ||
test("checks extensionComposerFile.json to be invalid root composer file", () => { | ||
test("checks extension composer.json to be invalid root composer file", () => { | ||
expect( | ||
isComposerRoot( | ||
resolve(__dirname, "fixtures/extensionComposerFile.json"), | ||
), | ||
isComposerRoot("/path/to/fixtures/composerProject/packages/composerExtension/composer.json") | ||
).toBe(false); | ||
}); | ||
test("checks libraryComposerFile.json to be invalid root composer file", () => { | ||
test("checks library composer.json to be invalid root composer file", () => { | ||
expect( | ||
isComposerRoot( | ||
resolve(__dirname, "fixtures/libraryComposerFile.json"), | ||
), | ||
isComposerRoot("/path/to/fixtures/composerProject/vendor/namespace/library/composer.json") | ||
).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("readJsonFile", () => { | ||
test("reads composer.json as json", () => { | ||
expect( | ||
readJsonFile("/path/to/fixtures/composerProject/vendor/namespace/library/composer.json") | ||
).toEqual({"type": "library"}); | ||
}); | ||
}); | ||
|
||
describe("determineComposerRoot", () => { | ||
test("determines composer root from extension path", () => { | ||
expect( | ||
determineComposerRoot("/path/to/fixtures/composerProject/packages/composerExtension") | ||
).toBe("/path/to/fixtures/composerProject"); | ||
}); | ||
test("determines composer root from library path", () => { | ||
expect( | ||
determineComposerRoot("/path/to/fixtures/composerProject/vendor/namespace/library") | ||
).toBe("/path/to/fixtures/composerProject"); | ||
}); | ||
test("determines composer root from root path", () => { | ||
expect( | ||
determineComposerRoot("/path/to/fixtures/composerProject") | ||
).toBe("/path/to/fixtures/composerProject"); | ||
}); | ||
test("determines composer root from other path", () => { | ||
expect( | ||
determineComposerRoot("/path/to/fixtures/composerProject/packages") | ||
).toBe("/path/to/fixtures/composerProject"); | ||
}); | ||
|
||
test("fail to determine composer root from extension path", () => { | ||
expect( | ||
determineComposerRoot("/path/to/fixtures/nonComposerProject/typo3conf/ext/non_composer_extension") | ||
).toBe("/path/to/fixtures/nonComposerProject/typo3conf/ext/non_composer_extension"); | ||
}); | ||
test("fail to determine composer root from extension path with fallback root specified", () => { | ||
expect( | ||
determineComposerRoot( | ||
"/path/to/fixtures/nonComposerProject/typo3conf/ext/non_composer_extension", | ||
"/path/to/fixtures/nonComposerProject", | ||
) | ||
).toBe("/path/to/fixtures/nonComposerProject"); | ||
}); | ||
}); |