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
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,25 @@ import { executeDevServer } from '../../index';
import { describeServeBuilder } from '../jasmine-helpers';
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';

describeServeBuilder(
executeDevServer,
DEV_SERVER_BUILDER_INFO,
(harness, setupTarget, isViteRun) => {
// TODO(fix-vite): currently this is broken in vite.
(isViteRun ? xdescribe : describe)('Behavior: "browser builder budgets"', () => {
beforeEach(() => {
setupTarget(harness, {
// Add a budget error for any file over 100 bytes
budgets: [{ type: BudgetType.All, maximumError: '100b' }],
optimization: true,
});
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
// TODO(fix-vite): currently this is broken in vite.
xdescribe('Behavior: "browser builder budgets"', () => {
beforeEach(() => {
setupTarget(harness, {
// Add a budget error for any file over 100 bytes
budgets: [{ type: BudgetType.All, maximumError: '100b' }],
optimization: true,
});
});

it('should ignore budgets defined in the "buildTarget" options', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
});
it('should ignore budgets defined in the "buildTarget" options', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
});

const { result } = await harness.executeOnce();
const { result } = await harness.executeOnce();

expect(result?.success).toBe(true);
});
expect(result?.success).toBe(true);
});
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,86 +15,74 @@ import { executeOnceAndFetch } from '../execute-fetch';
import { describeServeBuilder } from '../jasmine-helpers';
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';

describeServeBuilder(
executeDevServer,
DEV_SERVER_BUILDER_INFO,
(harness, setupTarget, isApplicationBuilder) => {
describe('Behavior: "conditional imports"', () => {
if (!isApplicationBuilder) {
it('requires esbuild', () => {
expect(true).toBeTrue();
});

return;
}

beforeEach(async () => {
setupTarget(harness);
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
describe('Behavior: "conditional imports"', () => {
beforeEach(async () => {
setupTarget(harness);

await setupConditionImport(harness);
});
await setupConditionImport(harness);
});

interface ImportsTestCase {
name: string;
mapping: unknown;
output?: string;
}
interface ImportsTestCase {
name: string;
mapping: unknown;
output?: string;
}

const GOOD_TARGET = './src/good.js';
const BAD_TARGET = './src/bad.js';
const GOOD_TARGET = './src/good.js';
const BAD_TARGET = './src/bad.js';

const testCases: ImportsTestCase[] = [
{ name: 'simple string', mapping: GOOD_TARGET },
{
name: 'default fallback without matching condition',
mapping: {
'never': BAD_TARGET,
'default': GOOD_TARGET,
},
const testCases: ImportsTestCase[] = [
{ name: 'simple string', mapping: GOOD_TARGET },
{
name: 'default fallback without matching condition',
mapping: {
'never': BAD_TARGET,
'default': GOOD_TARGET,
},
{
name: 'development condition',
mapping: {
'development': GOOD_TARGET,
'default': BAD_TARGET,
},
},
{
name: 'development condition',
mapping: {
'development': GOOD_TARGET,
'default': BAD_TARGET,
},
{
name: 'production condition',
mapping: {
'production': BAD_TARGET,
'default': GOOD_TARGET,
},
},
{
name: 'production condition',
mapping: {
'production': BAD_TARGET,
'default': GOOD_TARGET,
},
{
name: 'browser condition (in browser)',
mapping: {
'browser': GOOD_TARGET,
'default': BAD_TARGET,
},
},
{
name: 'browser condition (in browser)',
mapping: {
'browser': GOOD_TARGET,
'default': BAD_TARGET,
},
];
},
];

for (const testCase of testCases) {
describe(testCase.name, () => {
beforeEach(async () => {
await setTargetMapping(harness, testCase.mapping);
});
for (const testCase of testCases) {
describe(testCase.name, () => {
beforeEach(async () => {
await setTargetMapping(harness, testCase.mapping);
});

it('resolves to expected target', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
});
it('resolves to expected target', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
});

const { result, response } = await executeOnceAndFetch(harness, '/main.js');
const { result, response } = await executeOnceAndFetch(harness, '/main.js');

expect(result?.success).toBeTrue();
const output = await response?.text();
expect(output).toContain('good-value');
expect(output).not.toContain('bad-value');
});
expect(result?.success).toBeTrue();
const output = await response?.text();
expect(output).toContain('good-value');
expect(output).not.toContain('bad-value');
});
}
});
},
);
});
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,66 @@ import { executeDevServer } from '../../index';
import { describeServeBuilder } from '../jasmine-helpers';
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';

describeServeBuilder(
executeDevServer,
DEV_SERVER_BUILDER_INFO,
(harness, setupTarget, isViteRun) => {
// TODO(fix-vite): currently this is broken in vite.
(isViteRun ? xdescribe : describe)('Behavior: "i18n translation file watching"', () => {
beforeEach(() => {
harness.useProject('test', {
root: '.',
sourceRoot: 'src',
cli: {
cache: {
enabled: false,
},
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
// TODO(fix-vite): currently this is broken in vite.
xdescribe('Behavior: "i18n translation file watching"', () => {
beforeEach(() => {
harness.useProject('test', {
root: '.',
sourceRoot: 'src',
cli: {
cache: {
enabled: false,
},
i18n: {
locales: {
fr: 'src/locales/messages.fr.xlf',
},
},
i18n: {
locales: {
fr: 'src/locales/messages.fr.xlf',
},
});

setupTarget(harness, { localize: ['fr'] });
},
});

it('watches i18n translation files by default', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
watch: true,
});
setupTarget(harness, { localize: ['fr'] });
});

it('watches i18n translation files by default', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
watch: true,
});

await harness.writeFile(
'src/app/app.component.html',
`
await harness.writeFile(
'src/app/app.component.html',
`
<p id="hello" i18n="An introduction header for this sample">Hello {{ title }}! </p>
`,
);
);

await harness.writeFile('src/locales/messages.fr.xlf', TRANSLATION_FILE_CONTENT);
await harness.writeFile('src/locales/messages.fr.xlf', TRANSLATION_FILE_CONTENT);

await harness.executeWithCases([
async ({ result }) => {
expect(result?.success).toBe(true);
await harness.executeWithCases([
async ({ result }) => {
expect(result?.success).toBe(true);

const mainUrl = new URL('main.js', `${result?.baseUrl}`);
const response = await fetch(mainUrl);
expect(await response?.text()).toContain('Bonjour');
const mainUrl = new URL('main.js', `${result?.baseUrl}`);
const response = await fetch(mainUrl);
expect(await response?.text()).toContain('Bonjour');

await harness.modifyFile('src/locales/messages.fr.xlf', (content) =>
content.replace('Bonjour', 'Salut'),
);
},
async ({ result }) => {
expect(result?.success).toBe(true);
await harness.modifyFile('src/locales/messages.fr.xlf', (content) =>
content.replace('Bonjour', 'Salut'),
);
},
async ({ result }) => {
expect(result?.success).toBe(true);

const mainUrl = new URL('main.js', `${result?.baseUrl}`);
const response = await fetch(mainUrl);
expect(await response?.text()).toContain('Salut');
},
]);
});
const mainUrl = new URL('main.js', `${result?.baseUrl}`);
const response = await fetch(mainUrl);
expect(await response?.text()).toContain('Salut');
},
]);
});
},
);
});
});

const TRANSLATION_FILE_CONTENT = `
<?xml version="1.0" encoding="UTF-8" ?>
Expand Down
Loading