Skip to content

Commit

Permalink
Restore the use of regex to test error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Jul 7, 2023
1 parent 86b2110 commit 1af13dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
8 changes: 2 additions & 6 deletions packages/esbuild/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ test('@mdx-js/esbuild', async () => {
outfile: fileURLToPath(new URL('esbuild-md-as-mdx.js', import.meta.url)),
plugins: [esbuildMdx({format: 'mdx'})]
}),
new Error(
'Build failed with 1 error:\nerror: No loader is configured for ".md" files: test/esbuild.md'
),
/No loader is configured for "\.md" files/,
'should not handle `.md` files w/ `format: mdx`'
)

Expand All @@ -159,9 +157,7 @@ test('@mdx-js/esbuild', async () => {
outfile: fileURLToPath(new URL('esbuild-md-as-mdx.js', import.meta.url)),
plugins: [esbuildMdx({format: 'md'})]
}),
new Error(
'Build failed with 1 error:\nerror: No loader is configured for ".mdx" files: test/esbuild.mdx'
),
/No loader is configured for "\.mdx" files/,
'should not handle `.mdx` files w/ `format: md`'
)

Expand Down
35 changes: 10 additions & 25 deletions packages/mdx/test/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ test('compile', async () => {
assert.throws(
// @ts-expect-error: removed option.
() => compile('# hi!', {filepath: 'example.mdx'}),
new Error(
'`options.filepath` is no longer supported. Please see <https://mdxjs.com/migrating/v2/> for more information'
)
/`options.filepath` is no longer supported/,
'should throw when a removed option is passed'
)

assert.equal(
Expand Down Expand Up @@ -306,7 +305,7 @@ test('compile', async () => {
await run(compileSync('export var X = () => <Y />\n\n<X />'))
)
),
new ReferenceError('Y is not defined'),
/Y is not defined/,
'should throw on missing components in exported components'
)

Expand Down Expand Up @@ -465,9 +464,7 @@ test('compile', async () => {
async () => {
renderToStaticMarkup(React.createElement(await run(compileSync('<X />'))))
},
new Error(
'Expected component `X` to be defined: you likely forgot to import, pass, or provide it.'
),
/Expected component `X` to be defined/,
'should throw if a required component is not passed'
)

Expand All @@ -477,9 +474,7 @@ test('compile', async () => {
React.createElement(await run(compileSync('<a.b />')))
)
},
new Error(
'Expected object `a` to be defined: you likely forgot to import, pass, or provide it.'
),
/Expected object `a` to be defined/,
'should throw if a required member is not passed'
)

Expand All @@ -491,9 +486,7 @@ test('compile', async () => {
)
)
},
new Error(
'Expected component `a.b` to be defined: you likely forgot to import, pass, or provide it.'
),
/Expected component `a.b` to be defined/,
'should throw if a used member is not defined locally'
)

Expand All @@ -505,9 +498,7 @@ test('compile', async () => {
)
)
},
new Error(
'Expected object `x` to be defined: you likely forgot to import, pass, or provide it.'
),
/Expected object `x` to be defined/,
'should throw if a used member is not defined locally (JSX in a function)'
)

Expand Down Expand Up @@ -548,9 +539,7 @@ test('compile', async () => {
)
)
},
new Error(
'Expected component `X` to be defined: you likely forgot to import, pass, or provide it.\nIt’s referenced in your code at `1:1-1:6`'
),
/It’s referenced in your code at `1:1-1:6/,
'should pass more info to errors w/ `development: true`'
)

Expand All @@ -567,9 +556,7 @@ test('compile', async () => {
)
)
},
new Error(
'Expected object `a` to be defined: you likely forgot to import, pass, or provide it.\nIt’s referenced in your code at `1:5-1:12` in `folder/example.mdx`'
),
/It’s referenced in your code at `1:5-1:12` in `folder\/example.mdx`/,
'should show what file contains the error w/ `development: true`, and `path`'
)

Expand Down Expand Up @@ -603,9 +590,7 @@ test('compile', async () => {
)
)
},
new Error(
'Expected component `X` to be defined: you likely forgot to import, pass, or provide it.'
),
/Expected component `X` to be defined/,
'should throw if a required component is not passed or given to `MDXProvider`'
)

Expand Down

0 comments on commit 1af13dd

Please sign in to comment.