From f1b2fbdfb48bbb723620e477245c965e61d59e97 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:37:24 +0530 Subject: [PATCH 1/3] chore: fix error assertions --- test/Errors.test.js | 53 ++++++++++++++++++++++++++------------------- test/rc.test.js | 9 -------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/test/Errors.test.js b/test/Errors.test.js index 5df6e51..9e545ca 100644 --- a/test/Errors.test.js +++ b/test/Errors.test.js @@ -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: (.*)$/ +// }) +// }) + +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)/ }) }) diff --git a/test/rc.test.js b/test/rc.test.js index 0e58385..558e306 100644 --- a/test/rc.test.js +++ b/test/rc.test.js @@ -54,12 +54,3 @@ test('.postcssrc - {Object} - Process SSS', () => { }) }) }) - -describe('Load Config Error', () => { - test('no config found error', () => { - return postcssrc({}, 'ghostDir') - .catch(error => { - equal(error.message.startsWith("No PostCSS Config found in:"), true) - }) - }) -}) From ed24e4db701876c20f28fc88b8118d43aca54e59 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:46:56 +0530 Subject: [PATCH 2/3] organize a bit --- test/Errors.test.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/Errors.test.js b/test/Errors.test.js index 9e545ca..dae2b98 100644 --- a/test/Errors.test.js +++ b/test/Errors.test.js @@ -3,19 +3,25 @@ const { rejects } = require('node:assert') const postcssrc = require('../src/index.js') -// 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: (.*)$/ -// }) -// }) - describe('Loading Config - {Error}', () => { - test('no config found error', () => { + // FIXME: this is resolving to nearest postcss config (outside root) + // test('Missing File', async () => { + // await rejects(() => postcssrc({}, 'test/err'), { + // message: /^No PostCSS Config found in: (.*)$/ + // }) + // }) + + test('Missing Directory', () => { return rejects(() => postcssrc({}, 'ghostDir'), { message: /^No PostCSS Config found in: (.*)$/ }) }) + + test('TS - Syntax', () => { + return rejects(() => postcssrc({}, 'test/err/ts'), { + message: /^(Transform failed|ParseError)/ + }) + }) }) describe('Loading Plugins - {Error}', () => { @@ -69,9 +75,3 @@ describe('Loading Options - {Error}', () => { }) }) }) - -test('Loading TS Config - {Error} - Syntax', () => { - return rejects(() => postcssrc({}, 'test/err/ts'), { - message: /^(Transform failed|ParseError)/ - }) -}) From 150564bc29dbf7a17efc7230f9e9dfefda69e375 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:51:47 +0530 Subject: [PATCH 3/3] remove test --- test/Errors.test.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/Errors.test.js b/test/Errors.test.js index dae2b98..7d01af7 100644 --- a/test/Errors.test.js +++ b/test/Errors.test.js @@ -4,13 +4,6 @@ const { rejects } = require('node:assert') const postcssrc = require('../src/index.js') describe('Loading Config - {Error}', () => { - // FIXME: this is resolving to nearest postcss config (outside root) - // test('Missing File', async () => { - // await rejects(() => postcssrc({}, 'test/err'), { - // message: /^No PostCSS Config found in: (.*)$/ - // }) - // }) - test('Missing Directory', () => { return rejects(() => postcssrc({}, 'ghostDir'), { message: /^No PostCSS Config found in: (.*)$/