Skip to content

Commit

Permalink
test: replace pipes with for await (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen committed Aug 2, 2023
1 parent a8b1f6b commit 2f1df78
Show file tree
Hide file tree
Showing 34 changed files with 2,710 additions and 3,235 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"devDependencies": {
"@vitest/coverage-v8": "^0.33.0",
"better-than-before": "^1.0.0",
"concat-stream": "^2.0.0",
"conventional-changelog-core": "^5.0.0",
"eslint": "^8.0.0",
"eslint-config-standard": "^17.0.0",
Expand Down
150 changes: 98 additions & 52 deletions packages/conventional-changelog-angular/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import path from 'path'
import { describe, it, expect } from 'vitest'
import BetterThanBefore from 'better-than-before'
import {
TestTools,
runConventionalChangelog
} from '../../../tools/test-tools'
import conventionalChangelogCore from 'conventional-changelog-core'
import { TestTools } from '../../../tools/test-tools'
import preset from '../'

const { setups, preparing, tearsWithJoy } = BetterThanBefore()
Expand Down Expand Up @@ -72,11 +70,14 @@ tearsWithJoy(() => {
describe('conventional-changelog-angular', () => {
it('should work if there is no semver tag', async () => {
preparing(1)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('first build setup')
expect(chunk).toContain('**travis:** add TravisCI pipeline')
expect(chunk).toContain('**travis:** Continuously integrated.')
Expand All @@ -103,182 +104,227 @@ describe('conventional-changelog-angular', () => {
expect(chunk).not.toContain('revert')
expect(chunk).not.toContain('***:**')
expect(chunk).not.toContain(': Not backward compatible.')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should replace #[0-9]+ with GitHub issue URL', async () => {
preparing(2)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('[#133](https://github.com/conventional-changelog/conventional-changelog/issues/133)')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should remove the issues that already appear in the subject', async () => {
preparing(3)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('[#88](https://github.com/conventional-changelog/conventional-changelog/issues/88)')
expect(chunk).not.toContain('closes [#88](https://github.com/conventional-changelog/conventional-changelog/issues/88)')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should replace @username with GitHub user URL', async () => {
preparing(4)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('[@bcoe](https://github.com/bcoe)')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should not discard commit if there is BREAKING CHANGE', async () => {
preparing(5)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('Continuous Integration')
expect(chunk).toContain('Build System')
expect(chunk).toContain('Documentation')
expect(chunk).toContain('Styles')
expect(chunk).toContain('Code Refactoring')
expect(chunk).toContain('Tests')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should work if there is a semver tag', async () => {
preparing(6)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset,
outputUnreleased: true
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('some more features')
expect(chunk).not.toContain('BREAKING')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should work with unknown host', async () => {
preparing(6)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset,
pkg: {
path: path.join(__dirname, 'fixtures/_unknown-host.json')
}
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('(http://unknown/compare')
expect(chunk).toContain('](http://unknown/commits/')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should work specifying where to find a package.json using conventional-changelog-core', async () => {
preparing(7)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset,
pkg: {
path: path.join(__dirname, 'fixtures/_known-host.json')
}
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('(https://github.com/conventional-changelog/example/compare')
expect(chunk).toContain('](https://github.com/conventional-changelog/example/commit/')
expect(chunk).toContain('](https://github.com/conventional-changelog/example/issues/')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should fallback to the closest package.json when not providing a location for a package.json', async () => {
preparing(7)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('(https://github.com/conventional-changelog/conventional-changelog/compare')
expect(chunk).toContain('](https://github.com/conventional-changelog/conventional-changelog/commit/')
expect(chunk).toContain('](https://github.com/conventional-changelog/conventional-changelog/issues/')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should support non public GitHub repository locations', async () => {
preparing(7)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset,
pkg: {
path: path.join(__dirname, 'fixtures/_ghe-host.json')
}
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain('(https://github.internal.example.com/dlmr')
expect(chunk).toContain('(https://github.internal.example.com/conventional-changelog/internal/compare')
expect(chunk).toContain('](https://github.internal.example.com/conventional-changelog/internal/commit/')
expect(chunk).toContain('5](https://github.internal.example.com/conventional-changelog/internal/issues/5')
expect(chunk).toContain(' closes [#10](https://github.internal.example.com/conventional-changelog/internal/issues/10)')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should only replace with link to user if it is a username', async () => {
preparing(8)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).not.toContain('(https://github.com/5')
expect(chunk).toContain('(https://github.com/username')

expect(chunk).not.toContain('[@dummy](https://github.com/dummy)/package')
expect(chunk).toContain('bump @dummy/package from')
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})

it('should parse both default (Revert "<subject>") and custom (revert: <subject>) revert commits', async () => {
preparing(9)
let i = 0

const chunks = await runConventionalChangelog({
for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toMatch(/custom revert format/)
expect(chunk).toMatch(/default revert format/)
})
i++
}

expect(chunks).toHaveLength(1)
expect(i).toBe(1)
})
})
20 changes: 12 additions & 8 deletions packages/conventional-changelog-atom/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { describe, beforeAll, afterAll, it, expect } from 'vitest'
import {
TestTools,
runConventionalChangelog
} from '../../../tools/test-tools'
import conventionalChangelogCore from 'conventional-changelog-core'
import { TestTools } from '../../../tools/test-tools'
import preset from '../'

let testTools
Expand All @@ -24,16 +22,22 @@ describe('conventional-changelog-atom', () => {
})

it('should work if there is no semver tag', async () => {
const chunks = await runConventionalChangelog({
let i = 0

for await (let chunk of conventionalChangelogCore({
cwd: testTools.cwd,
config: preset
}, (chunk) => {
})) {
chunk = chunk.toString()

expect(chunk).toContain(':arrow_down:')
expect(chunk).toContain('`updateContentDimensions` when model changes')
expect(chunk).toContain(':arrow_up:')
expect(chunk).toContain('one-dark/light-ui@v1.0.1')
})

expect(chunks).toHaveLength(1)
i++
}

expect(i).toBe(1)
})
})

0 comments on commit 2f1df78

Please sign in to comment.