Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Apr 10, 2023
1 parent 8b7f030 commit 9b11d8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/build/__tests__/basic.ts
Expand Up @@ -1241,7 +1241,7 @@ test("importing css fails with a nice error", async () => {
"src/blah.css": "",
});
await expect(build(dir)).rejects.toMatchInlineSnapshot(
`[Error: 🎁 @scope/test only .ts, .tsx, .js, .jsx, and .json files can be imported but "/private/var/folders/ct/tgr1gzss4wx58r9t7f0yp8_00000gn/T/51ae39dfcd9235458107c14021cd4c05/src/blah.css" is imported in "src/index.js"]`
`[Error: 🎁 @scope/test only .ts, .tsx, .js, .jsx, and .json files can be imported but "blah.css" is imported in "src/index.js"]`
);
});

Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/build/__tests__/other.ts
Expand Up @@ -517,10 +517,9 @@ test("module imported outside package directory", async () => {
try {
await build(tmpPath);
} catch (err) {
expect(err.message).toMatchInlineSnapshot(`
"🎁 @imports-outside-pkg-dir/pkg-a all relative imports in a package should only import modules inside of their package directory but "src/index.js" is importing "../../some-file"
🎁 @imports-outside-pkg-dir/pkg-a all relative imports in a package should only import modules inside of their package directory but "src/index.js" is importing "/private/var/folders/ct/tgr1gzss4wx58r9t7f0yp8_00000gn/T/7b8193c2854b775119af269533486790/some-file.js""
`);
expect(err.message).toMatchInlineSnapshot(
`"🎁 @imports-outside-pkg-dir/pkg-a all relative imports in a package should only import modules inside of their package directory but "src/index.js" is importing "../../some-file""`
);
return;
}
expect(true).toBe(false);
Expand Down
22 changes: 14 additions & 8 deletions packages/cli/src/rollup-plugins/resolve.ts
Expand Up @@ -43,7 +43,11 @@ export function resolveErrorsPlugin(
if (resolved.id.startsWith(pkg.directory)) {
if (!resolved.external && !allowedExtensionRegex.test(resolved.id)) {
warnings.add(
`only .ts, .tsx, .js, .jsx, and .json files can be imported but "${source}" is imported in ${
`only .ts, .tsx, .js, .jsx, and .json files can be imported but "${
importer === undefined
? source
: normalizePath(path.relative(path.dirname(importer), source))
}" is imported in ${
importer
? `"${normalizePath(path.relative(pkg.directory, importer))}"`
: "a module"
Expand All @@ -55,13 +59,15 @@ export function resolveErrorsPlugin(
return resolved;
}
if (isUmd) return resolved;
warnings.add(
`all relative imports in a package should only import modules inside of their package directory but ${
importer
? `"${normalizePath(path.relative(pkg.directory, importer))}"`
: "a module"
} is importing "${source}"`
);
if (resolved.id !== source) {
warnings.add(
`all relative imports in a package should only import modules inside of their package directory but ${
importer
? `"${normalizePath(path.relative(pkg.directory, importer))}"`
: "a module"
} is importing "${source}"`
);
}

return false;
},
Expand Down

0 comments on commit 9b11d8b

Please sign in to comment.