-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also changed empty test duration to output `0` for consistency.
- Loading branch information
Showing
22 changed files
with
2,097 additions
and
330 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Test | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "12.x" | ||
registry-url: https://registry.npmjs.org/ | ||
- uses: actions/cache@v1 | ||
with: | ||
path: node_modules | ||
key: yarn-${{ hashFiles('yarn.lock') }} | ||
restore-keys: | | ||
yarn- | ||
- run: yarn install --frozen-lockfile | ||
- run: yarn test |
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,16 @@ | ||
|
||
<DESCRIBE::>group 1 | ||
|
||
<IT::>test 1 | ||
|
||
<PASSED::>Test Passed | ||
|
||
<COMPLETEDIN::>1 | ||
|
||
<IT::>test 2 | ||
|
||
<PASSED::>Test Passed | ||
|
||
<COMPLETEDIN::>0 | ||
|
||
<COMPLETEDIN::> |
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,8 @@ | ||
describe("group 1", () => { | ||
test("test 1", () => { | ||
expect(1).toBe(1); | ||
}); | ||
test("test 2", () => { | ||
expect(1).toBe(1); | ||
}); | ||
}); |
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,20 @@ | ||
|
||
<DESCRIBE::>group 1 | ||
|
||
<IT::>test 1 | ||
|
||
<PASSED::>Test Passed | ||
|
||
<COMPLETEDIN::>1 | ||
|
||
<COMPLETEDIN::> | ||
|
||
<DESCRIBE::>group 2 | ||
|
||
<IT::>test 1 | ||
|
||
<PASSED::>Test Passed | ||
|
||
<COMPLETEDIN::>1 | ||
|
||
<COMPLETEDIN::> |
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,11 @@ | ||
describe("group 1", () => { | ||
test("test 1", () => { | ||
expect(1).toBe(1); | ||
}); | ||
}); | ||
|
||
describe("group 2", () => { | ||
test("test 1", () => { | ||
expect(1).toBe(1); | ||
}); | ||
}); |
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,14 @@ | ||
|
||
<DESCRIBE::>group 1 | ||
|
||
<DESCRIBE::>group 1 1 | ||
|
||
<IT::>test 1 | ||
|
||
<PASSED::>Test Passed | ||
|
||
<COMPLETEDIN::>1 | ||
|
||
<COMPLETEDIN::> | ||
|
||
<COMPLETEDIN::> |
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,7 @@ | ||
describe("group 1", () => { | ||
describe("group 1 1", () => { | ||
test("test 1", () => { | ||
expect(1).toBe(1); | ||
}); | ||
}); | ||
}); |
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,14 @@ | ||
|
||
<DESCRIBE::>group 1 | ||
|
||
<IT::>test 1 | ||
|
||
<FAILED::>Test Failed | ||
|
||
<LOG:HTML:Failure><pre class="ansi"><code>Error: expect(received).toBe(expected) // Object.is equality<:LF:><:LF:>Expected: 2<:LF:>Received: 1</code></pre> | ||
|
||
<COMPLETEDIN::>3 | ||
|
||
<COMPLETEDIN::> | ||
|
||
<LOG:HTML:Failures><pre class="ansi"><code>● group 1 › test 1<:LF:><:LF:> expect(received).toBe(expected) // Object.is equality<:LF:><:LF:> Expected: 2<:LF:> Received: 1<:LF:><:LF:> 1 | describe("group 1", () => {<:LF:> 2 | test("test 1", () => {<:LF:> > 3 | expect(1).toBe(2);<:LF:> | ^<:LF:> 4 | });<:LF:> 5 | });<:LF:> 6 | <:LF:><:LF:> at Object.<anonymous> (fixtures/single-group-failing.js:3:15)</code></pre> |
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 @@ | ||
describe("group 1", () => { | ||
test("test 1", () => { | ||
expect(1).toBe(2); | ||
}); | ||
}); |
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,10 @@ | ||
|
||
<DESCRIBE::>group 1 | ||
|
||
<IT::>test 1 | ||
|
||
<PASSED::>Test Passed | ||
|
||
<COMPLETEDIN::>2 | ||
|
||
<COMPLETEDIN::> |
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 @@ | ||
describe("group 1", () => { | ||
test("test 1", () => { | ||
expect(1).toBe(1); | ||
}); | ||
}); |
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,10 @@ | ||
|
||
<IT::>test 1 | ||
|
||
<FAILED::>Test Failed | ||
|
||
<LOG:HTML:Failure><pre class="ansi"><code>Error: expect(received).toBe(expected) // Object.is equality<:LF:><:LF:>Expected: 2<:LF:>Received: 1</code></pre> | ||
|
||
<COMPLETEDIN::>3 | ||
|
||
<LOG:HTML:Failures><pre class="ansi"><code>● test 1<:LF:><:LF:> expect(received).toBe(expected) // Object.is equality<:LF:><:LF:> Expected: 2<:LF:> Received: 1<:LF:><:LF:> 1 | test("test 1", () => {<:LF:> > 2 | expect(1).toBe(2);<:LF:> | ^<:LF:> 3 | });<:LF:> 4 | <:LF:><:LF:> at Object.<anonymous> (fixtures/toplevel-test-failing.js:2:13)</code></pre> |
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,3 @@ | ||
test("test 1", () => { | ||
expect(1).toBe(2); | ||
}); |
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,6 @@ | ||
|
||
<IT::>test 1 | ||
|
||
<PASSED::>Test Passed | ||
|
||
<COMPLETEDIN::>2 |
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,3 @@ | ||
test("test 1", () => { | ||
expect(1).toBe(1); | ||
}); |
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,7 @@ | ||
#!/bin/bash | ||
# ./gen-fixture.sh fixtures/example.js | ||
# ./gen-fixture.sh fixtures/example.js expected | ||
# ./gen-fixture.sh fixtures/example.js sample | ||
# for f in $(ls fixtures/*.js); do ./gen-fixture.sh "$f"; done | ||
|
||
./node_modules/.bin/jest $1 --reporters=./lib/codewars-reporter.js --testMatch='**/fixtures/*.js' > "${1%.js}.${2:-expected}.txt" |
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,4 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { promisify } from "util"; | ||
|
||
import execa from "execa"; | ||
import escapeRegExp from "escape-string-regexp"; | ||
|
||
const readFile = promisify(fs.readFile); | ||
const access = promisify(fs.access); | ||
const exists = async (path: string) => { | ||
try { | ||
await access(path); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
const structureMatches = (a: string, b: string) => | ||
expect( | ||
a.match(/<(?:DESCRIBE|IT|PASSED|FAILED|ERROR|COMPLETEDIN)::>/g)!.join("") | ||
).toStrictEqual( | ||
b.match(/<(?:DESCRIBE|IT|PASSED|FAILED|ERROR|COMPLETEDIN)::>/g)!.join("") | ||
); | ||
|
||
describe("CodewarsReporter", () => { | ||
const cwd = path.join(__dirname, ".."); | ||
const fixturesDir = path.join(__dirname, "..", "fixtures"); | ||
const files = fs.readdirSync(fixturesDir).filter((f) => f.endsWith(".js")); | ||
for (const file of files) { | ||
it(file.replace(/\.js$/, ""), async () => { | ||
const { stdout } = await execa( | ||
"jest", | ||
[ | ||
path.join(fixturesDir, file), | ||
"--reporters=./lib/codewars-reporter.js", | ||
"--testMatch='**/fixtures/*.js'", | ||
], | ||
{ | ||
cwd, | ||
preferLocal: true, | ||
stripFinalNewline: false, | ||
reject: false, | ||
} | ||
); | ||
const expectedFile = path.join( | ||
fixturesDir, | ||
file.replace(/\.js$/, ".expected.txt") | ||
); | ||
|
||
if (await exists(expectedFile)) { | ||
const expected = await readFile(expectedFile, { | ||
encoding: "utf-8", | ||
}); | ||
// Allow duration to change. | ||
const expectedPattern = new RegExp( | ||
escapeRegExp(expected).replace(/(?<=<COMPLETEDIN::>)\d+/g, "\\d+") | ||
); | ||
expect(stdout).toMatch(expectedPattern); | ||
} else { | ||
const samplePath = path.join( | ||
fixturesDir, | ||
file.replace(/\.js$/, ".sample.txt") | ||
); | ||
const sample = await readFile(samplePath, { | ||
encoding: "utf-8", | ||
}); | ||
structureMatches(stdout, sample); | ||
} | ||
}); | ||
} | ||
}); |
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
Oops, something went wrong.