Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix error assertions #264

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions test/Errors.test.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,77 @@
const { describe, test } = require('node:test')
const { match } = require('node:assert')
const { rejects } = require('node:assert')

const postcssrc = require('../src/index.js')

test('Loading Config - {Error}', () => {
return postcssrc({}, 'test/err').catch(err => {
match(err.message, /^No PostCSS Config found in: (.*)$/)
// FIXME: this is resolving to nearest postcss config (outside root)
// test('Loading Config - {Error}', async () => {
// await rejects(() => postcssrc({}, 'test/err'), {
// message: /^No PostCSS Config found in: (.*)$/
// })
// })
Copy link
Contributor Author

@brc-dd brc-dd Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fully sure what's the expected behavior here, but this is not throwing any error and resolving to test/postcss.config.mjs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this test never moved to match area (this is why rejects is better).

As I understand it should ignore error in broken config and return No PostCSS Config found in. What is current behaviour in this test?

Copy link
Contributor Author

@brc-dd brc-dd Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, currently there is no postcssrc file directly inside test/err. Running postcssrc({}, 'test/err') is not failing and returning content from test/postcss.config.mjs (one directory up the passed directory). Should it fail if there is no config directly inside the specified path?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s remove test. It is rare case and test didn’t work for a while.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


describe('Loading Config - {Error}', () => {
test('no config found error', () => {
return rejects(() => postcssrc({}, 'ghostDir'), {
message: /^No PostCSS Config found in: (.*)$/
})
})
})

describe('Loading Plugins - {Error}', () => {
test('Plugin - {Type} - Invalid', () => {
return postcssrc({}, 'test/err/plugins').catch(err => {
match(err.message, /^Invalid PostCSS Plugin found at: (.*)\n\n\(@.*\)$/)
return rejects(() => postcssrc({}, 'test/err/plugins'), {
message: /^Invalid PostCSS Plugin found at: (.*)\n\n\(@.*\)$/
})
})

test('Plugin - {Object}', () => {
return postcssrc({}, 'test/err/plugins/object').catch(err => {
match(err.message, /^Loading PostCSS Plugin failed: .*$/m)
return rejects(() => postcssrc({}, 'test/err/plugins/object'), {
message: /^Loading PostCSS Plugin failed: .*$/m
})
})

test('Plugin - {Object} - Options', () => {
return postcssrc({}, 'test/err/plugins/object/options').catch(err => {
match(err.message, /^Loading PostCSS Plugin failed: .*$/m)
return rejects(() => postcssrc({}, 'test/err/plugins/object/options'), {
message: /^Loading PostCSS Plugin failed: .*$/m
})
})

test('Plugin - {Array}', () => {
return postcssrc({}, 'test/err/plugins/array').catch(err => {
match(err.message, /^Cannot find (.*)$/m)
return rejects(() => postcssrc({}, 'test/err/plugins/array'), {
message: /^Cannot find (.*)$/m
})
})

test('Plugin - {Array} - Options', () => {
return postcssrc({}, 'test/err/plugins/array/options').catch(err => {
match(err.message, /^Cannot find (.*)$/m)
return rejects(() => postcssrc({}, 'test/err/plugins/array/options'), {
message: /^Cannot find (.*)$/m
})
})
})

describe('Loading Options - {Error}', () => {
test('Parser - {String}', () => {
return postcssrc({}, 'test/err/options/parser').catch(err => {
match(err.message, /^Loading PostCSS Parser failed: .*$/m)
return rejects(() => postcssrc({}, 'test/err/options/parser'), {
message: /^Loading PostCSS Parser failed: .*$/m
})
})

test('Syntax - {String}', () => {
return postcssrc({}, 'test/err/options/syntax').catch(err => {
match(err.message, /^Loading PostCSS Syntax failed: .*$/m)
return rejects(() => postcssrc({}, 'test/err/options/syntax'), {
message: /^Loading PostCSS Syntax failed: .*$/m
})
})

test('Stringifier - {String}', () => {
return postcssrc({}, 'test/err/options/stringifier').catch(err => {
match(err.message, /^Loading PostCSS Stringifier failed: .*$/m)
return rejects(() => postcssrc({}, 'test/err/options/stringifier'), {
message: /^Loading PostCSS Stringifier failed: .*$/m
})
})
})

test('Loading TS Config - {Error} - Syntax', () => {
return postcssrc({}, 'test/err/ts').catch(err => {
match(err.message, /^(Transform failed|ParseError)/)
return rejects(() => postcssrc({}, 'test/err/ts'), {
message: /^(Transform failed|ParseError)/
})
})
9 changes: 0 additions & 9 deletions test/rc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,3 @@ test('.postcssrc - {Object} - Process SSS', () => {
})
})
})

describe('Load Config Error', () => {
ai marked this conversation as resolved.
Show resolved Hide resolved
test('no config found error', () => {
return postcssrc({}, 'ghostDir')
.catch(error => {
equal(error.message.startsWith("No PostCSS Config found in:"), true)
})
})
})