-
Notifications
You must be signed in to change notification settings - Fork 29
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
1 parent
21c6cc0
commit cdb4f1a
Showing
2 changed files
with
81 additions
and
63 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
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,78 +1,97 @@ | ||
const index = require('./index'); | ||
const index = require("./index"); | ||
const path = require("path"); | ||
const fs = require("fs").promises; | ||
|
||
describe('find test location', () => { | ||
let testReportFile; | ||
let testCase; | ||
|
||
describe('given single module archetype', () => { | ||
beforeAll(async () => { | ||
testReportFile = resolve("target/surefire-reports/TEST-dummy.xml"); | ||
testCase = { | ||
classname: "org.dummy.ClassTest", | ||
name: "methodTest" | ||
}; | ||
|
||
await addFile( | ||
'src/main/java/org/dummy/ClassTest.java', | ||
'package org.dummy;\n' + | ||
'class ClassTest {\n' + | ||
'void methodTest() { }\n' + | ||
'}'); | ||
|
||
await addFile('src/main/java/org/dummy2/ClassTest.java', '/* empty */'); | ||
}); | ||
|
||
afterAll(clearFiles); | ||
|
||
it('should find path of the class', async () => { | ||
let {filePath, line} = await index.findTestLocation(testReportFile, testCase); | ||
describe("find test location", () => { | ||
let testReportFile; | ||
let testCase; | ||
|
||
describe("given single module archetype", () => { | ||
beforeAll(async () => { | ||
testReportFile = resolve("target/surefire-reports/TEST-dummy.xml"); | ||
testCase = { | ||
classname: "org.dummy.ClassTest", | ||
name: "methodTest", | ||
}; | ||
|
||
await addFile( | ||
"src/main/java/org/dummy/ClassTest.java", | ||
"package org.dummy;\n" + | ||
"class ClassTest {\n" + | ||
"void methodTest() { }\n" + | ||
"}" | ||
); | ||
|
||
await addFile("src/main/java/org/dummy2/ClassTest.java", "/* empty */"); | ||
}); | ||
|
||
expect(filePath).toBe(resolve('src/main/java/org/dummy/ClassTest.java')); | ||
}); | ||
afterAll(clearFiles); | ||
|
||
it('should find line of the method', async () => { | ||
let {filePath, line} = await index.findTestLocation(testReportFile, testCase); | ||
it("should find path of the class", async () => { | ||
let { filePath, line } = await index.findTestLocation( | ||
testReportFile, | ||
testCase | ||
); | ||
|
||
expect(line).toBe(3); | ||
}); | ||
expect(filePath).toBe(resolve("src/main/java/org/dummy/ClassTest.java")); | ||
}); | ||
|
||
describe('given multiple gradle modules', () => { | ||
beforeAll(async () => { | ||
testReportFile = resolve("very_long_module1/build/test-results/test/TEST-dummy.xml"); | ||
testCase = { | ||
classname: "org.dummy.ClassTest", | ||
name: "methodTest" | ||
}; | ||
it("should find line of the method", async () => { | ||
let { filePath, line } = await index.findTestLocation( | ||
testReportFile, | ||
testCase | ||
); | ||
|
||
await addFile('src/main/java/org/dummy/ClassTest.java', ''); | ||
await addFile('very_long_module1/src/main/java/org/dummy/ClassTest.java', ''); | ||
await addFile('module2/src/main/java/org/dummy/ClassTest.java', ''); | ||
}); | ||
expect(line).toBe(3); | ||
}); | ||
}); | ||
|
||
describe("given multiple gradle modules", () => { | ||
beforeAll(async () => { | ||
testReportFile = resolve( | ||
"very_long_module1/build/test-results/test/TEST-dummy.xml" | ||
); | ||
testCase = { | ||
$: { | ||
classname: "org.dummy.ClassTest", | ||
name: "methodTest", | ||
}, | ||
}; | ||
|
||
await addFile("src/main/java/org/dummy/ClassTest.java", ""); | ||
await addFile( | ||
"very_long_module1/src/main/java/org/dummy/ClassTest.java", | ||
"" | ||
); | ||
await addFile("module2/src/main/java/org/dummy/ClassTest.java", ""); | ||
}); | ||
|
||
afterAll(clearFiles); | ||
afterAll(clearFiles); | ||
|
||
it('should find path of the class in the good module', async () => { | ||
let {filePath, line} = await index.findTestLocation(testReportFile, testCase); | ||
it("should find path of the class in the good module", async () => { | ||
let { filePath, line } = await index.findTestLocation( | ||
testReportFile, | ||
testCase | ||
); | ||
|
||
expect(filePath).toBe(resolve('very_long_module1/src/main/java/org/dummy/ClassTest.java')); | ||
}); | ||
expect(filePath).toBe( | ||
resolve("very_long_module1/src/main/java/org/dummy/ClassTest.java") | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
async function addFile(filePath, content) { | ||
filePath = 'tmp/' + filePath; | ||
let dirname = path.dirname(filePath); | ||
await fs.mkdir(dirname, { recursive: true }); | ||
await fs.writeFile(filePath, content); | ||
filePath = "tmp/" + filePath; | ||
let dirname = path.dirname(filePath); | ||
await fs.mkdir(dirname, { recursive: true }); | ||
await fs.writeFile(filePath, content); | ||
} | ||
|
||
async function clearFiles() { | ||
await fs.rmdir('tmp', { recursive: true }); | ||
await fs.rmdir("tmp", { recursive: true }); | ||
} | ||
|
||
function resolve(filePath) { | ||
return path.resolve('tmp/' + filePath); | ||
return path.resolve("tmp/" + filePath); | ||
} |