Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ jobs:

- run: pnpm install --frozen-lockfile

- run: pnpm build

- run: pnpm test
4 changes: 4 additions & 0 deletions tests/cases/gts/comment-with-template.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// A comment before template
<template>
<div>hello</div>
</template>
8 changes: 8 additions & 0 deletions tests/unit-tests/__snapshots__/format.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>;
"
`;

exports[`format > config > default > it formats ../cases/gts/comment-with-template.gts 1`] = `
"// A comment before template
<template>
<div>hello</div>
</template>
"
`;

exports[`format > config > default > it formats ../cases/gts/complex.gts 1`] = `
"import { on } from "@ember/modifier";
import { service } from "@ember/service";
Expand Down
32 changes: 32 additions & 0 deletions tests/unit-tests/build-externals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { readFileSync } from 'node:fs';
import path from 'node:path';

import { describe, expect, test } from 'vitest';

describe('build externals', () => {
const distributionPath = path.resolve(
import.meta.dirname,
'../../dist/prettier-plugin-ember-template-tag.js',
);

test('prettier/plugins/estree is externalized, not bundled', () => {
const distribution = readFileSync(distributionPath, 'utf8');

// The dist should reference estree as an external dependency (require or import)
expect(distribution).toMatch(
/require\(["']prettier\/plugins\/estree["']\)|from\s+["']prettier\/plugins\/estree["']/,
);

// The dist should NOT contain estree printer internals (canAttachComment is
// a function from the estree printer that would be present if bundled)
expect(distribution).not.toMatch(/function\s+\w*canAttachComment/);
});

test('prettier/plugins/babel is externalized, not bundled', () => {
const distribution = readFileSync(distributionPath, 'utf8');

expect(distribution).toMatch(
/require\(["']prettier\/plugins\/babel["']\)|from\s+["']prettier\/plugins\/babel["']/,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

covering cjs/esm cases (esm - for future use)

);
});
});
8 changes: 8 additions & 0 deletions tests/unit-tests/config/__snapshots__/semi-false.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>
"
`;

exports[`config > semi: false > it formats ../cases/gts/comment-with-template.gts 1`] = `
"// A comment before template
<template>
<div>hello</div>
</template>
"
`;

exports[`config > semi: false > it formats ../cases/gts/complex.gts 1`] = `
"import { on } from "@ember/modifier"
import { service } from "@ember/service"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>;
"
`;

exports[`config > templateExportDefault: true > it formats ../cases/gts/comment-with-template.gts 1`] = `
"// A comment before template
<template>
<div>hello</div>
</template>
"
`;

exports[`config > templateExportDefault: true > it formats ../cases/gts/complex.gts 1`] = `
"import { on } from "@ember/modifier";
import { service } from "@ember/service";
Expand Down
4 changes: 2 additions & 2 deletions vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default defineConfig({
external: [
'content-tag',
'prettier',
'prettier/plugins/estree.js',
'prettier/plugins/babel.js',
'prettier/plugins/estree',
'prettier/plugins/babel',
],
},
lib: {
Expand Down