@@ -292,3 +292,328 @@ tsAppScenarios
292
292
} ) ;
293
293
} ) ;
294
294
} ) ;
295
+
296
+ tsAppScenarios
297
+ . only ( 'release' )
298
+ . map ( 'vite-internals-with-base-path' , app => {
299
+ // These are for a custom testem setup that will let us do runtime tests
300
+ // inside `vite dev` rather than only against the output of `vite build`.
301
+ //
302
+ // Most apps should run their CI against `vite build`, as that's closer to
303
+ // production. And they can do development tests directly in brower against
304
+ // `vite dev` at `/tests/index.html`. We're doing `vite dev` in CI here
305
+ // because we're testing the development experience itself.
306
+ app . linkDevDependency ( 'testem' , { baseDir : __dirname } ) ;
307
+ app . linkDevDependency ( '@embroider/test-support' , { baseDir : __dirname } ) ;
308
+
309
+ app . linkDevDependency ( 'ember-page-title' , { baseDir : __dirname } ) ;
310
+ app . linkDevDependency ( 'ember-welcome-page' , { baseDir : __dirname } ) ;
311
+ app . mergeFiles ( {
312
+ 'testem-dev.js' : `
313
+ 'use strict';
314
+
315
+ module.exports = {
316
+ test_page: 'sub-dir/tests/index.html?hidepassed',
317
+ disable_watching: true,
318
+ launch_in_ci: ['Chrome'],
319
+ launch_in_dev: ['Chrome'],
320
+ browser_start_timeout: 120,
321
+ browser_args: {
322
+ Chrome: {
323
+ ci: [
324
+ // --no-sandbox is needed when running Chrome inside a container
325
+ process.env.CI ? '--no-sandbox' : null,
326
+ '--headless',
327
+ '--disable-dev-shm-usage',
328
+ '--disable-software-rasterizer',
329
+ '--mute-audio',
330
+ '--remote-debugging-port=0',
331
+ '--window-size=1440,900',
332
+ ].filter(Boolean),
333
+ },
334
+ },
335
+ middleware: [
336
+ require('@embroider/test-support/testem-proxy').testemProxy('http://localhost:4200')
337
+ ],
338
+ };
339
+ ` ,
340
+
341
+ 'testem.js' : `
342
+ 'use strict';
343
+
344
+ if (typeof module !== 'undefined') {
345
+ module.exports = {
346
+ test_page: 'sub-dir/tests/index.html?hidepassed',
347
+ disable_watching: true,
348
+ launch_in_ci: ['Chrome'],
349
+ launch_in_dev: ['Chrome'],
350
+ browser_start_timeout: 120,
351
+ browser_args: {
352
+ Chrome: {
353
+ ci: [
354
+ // --no-sandbox is needed when running Chrome inside a container
355
+ process.env.CI ? '--no-sandbox' : null,
356
+ '--headless',
357
+ '--disable-dev-shm-usage',
358
+ '--disable-software-rasterizer',
359
+ '--mute-audio',
360
+ '--remote-debugging-port=0',
361
+ '--window-size=1440,900',
362
+ ].filter(Boolean),
363
+ },
364
+ },
365
+ };
366
+ }
367
+
368
+ ` ,
369
+
370
+ config : {
371
+ 'environment.js' : `
372
+ 'use strict';
373
+
374
+ module.exports = function (environment) {
375
+ const ENV = {
376
+ modulePrefix: 'app-template',
377
+ environment,
378
+ rootURL: '/sub-dir/',
379
+ locationType: 'history',
380
+ EmberENV: {
381
+ EXTEND_PROTOTYPES: false,
382
+ FEATURES: {
383
+ // Here you can enable experimental features on an ember canary build
384
+ // e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
385
+ },
386
+ },
387
+
388
+ APP: {
389
+ // Here you can pass flags/options to your application instance
390
+ // when it is created
391
+ },
392
+ };
393
+
394
+ if (environment === 'development') {
395
+ // ENV.APP.LOG_RESOLVER = true;
396
+ // ENV.APP.LOG_ACTIVE_GENERATION = true;
397
+ // ENV.APP.LOG_TRANSITIONS = true;
398
+ // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
399
+ // ENV.APP.LOG_VIEW_LOOKUPS = true;
400
+ }
401
+
402
+ if (environment === 'test') {
403
+ // Testem prefers this...
404
+ ENV.locationType = 'none';
405
+
406
+ // keep test console output quieter
407
+ ENV.APP.LOG_ACTIVE_GENERATION = false;
408
+ ENV.APP.LOG_VIEW_LOOKUPS = false;
409
+
410
+ ENV.APP.rootElement = '#ember-testing';
411
+ ENV.APP.autoboot = false;
412
+ }
413
+
414
+ if (environment === 'production') {
415
+ // here you can enable a production-specific feature
416
+ }
417
+
418
+ return ENV;
419
+ };
420
+ ` ,
421
+ } ,
422
+
423
+ app : {
424
+ components : {
425
+ 'alpha.js' : `
426
+ import Component from '@glimmer/component';
427
+ export default class extends Component {
428
+ message = "alpha";
429
+ }
430
+ ` ,
431
+ 'alpha.hbs' : `
432
+ <div class="alpha">{{this.message}}</div>
433
+ <Beta />
434
+ ` ,
435
+ 'gamma.js' : `
436
+ globalThis.gammaLoaded = (globalThis.gammaLoaded ?? 0) + 1;
437
+ import Component from '@glimmer/component';
438
+ export default class extends Component {
439
+ message = "gamma";
440
+ }
441
+ ` ,
442
+ 'gamma.hbs' : `
443
+ <div class="gamma">{{this.message}}</div>
444
+ ` ,
445
+ 'epsilon.hbs' : `<div class="epsilon">Epsilon</div>` ,
446
+ 'fancy-button.hbs' : `<h1>I'm fancy</h1>` ,
447
+ 'delta.js' : `
448
+ import Component from '@glimmer/component';
449
+ export default class extends Component {
450
+ message = "delta";
451
+ }
452
+ ` ,
453
+ } ,
454
+ templates : {
455
+ 'application.hbs' : `
456
+ {{page-title "MyApp"}}
457
+ {{outlet}}
458
+ ` ,
459
+ 'index.hbs' : `
460
+ <FancyButton />
461
+ <WelcomePage />
462
+ ` ,
463
+ } ,
464
+ lib : {
465
+ 'app-lib-one.js' : `
466
+ globalThis.appLibOneLoaded = (globalThis.appLibOneLoaded ?? 0) + 1;
467
+ export default function() { return 'app-lib-one'; }
468
+ ` ,
469
+ 'app-lib-two.js' : `
470
+ globalThis.appLibTwoLoaded = (globalThis.appLibTwoLoaded ?? 0) + 1;
471
+ export default function() { return 'app-lib-two'; }
472
+ ` ,
473
+ } ,
474
+ } ,
475
+ tests : {
476
+ integration : {
477
+ components : {
478
+ 'example-test.js' : `
479
+ import { module, test } from 'qunit';
480
+ import { setupRenderingTest } from 'app-template/tests/helpers';
481
+ import { render } from '@ember/test-helpers';
482
+ import { hbs } from 'ember-cli-htmlbars';
483
+ import { appLibOne as libOneViaAddon, appLibTwo as libTwoViaAddon } from 'app-template/v1-example-addon';
484
+ import appLibOne from 'app-template/lib/app-lib-one';
485
+ import appLibTwo from 'app-template/lib/app-lib-two';
486
+
487
+ module('Integration | Component | example', function (hooks) {
488
+ setupRenderingTest(hooks);
489
+
490
+ test('nesting between app and addon components', async function (assert) {
491
+ await render(hbs\`<Alpha /><Gamma />\`);
492
+
493
+ // Alpha in the app...
494
+ assert.dom('.alpha').hasText('alpha');
495
+
496
+ // calls beta in the addon...
497
+ assert.dom('.beta').hasText('beta');
498
+
499
+ // which calls gamma in the app
500
+ // while the app itself also directly galls Gamma.
501
+ // We want to ensure that we get the same copy of Gamma via both paths.
502
+ assert.dom('.gamma').exists({ count: 2 })
503
+
504
+ assert.strictEqual(globalThis.gammaLoaded, 1, 'gamma only evaluated once');
505
+ });
506
+
507
+ test("addon depends on an app's hbs-only component", async function (assert) {
508
+ await render(hbs\`<Zeta />\`);
509
+ assert.dom('.zeta').hasText('Zeta');
510
+ assert.dom('.epsilon').hasText('Epsilon');
511
+ });
512
+
513
+ test("paired component between app and addon", async function (assert) {
514
+ await render(hbs\`<Delta />\`);
515
+ assert.dom('.delta').hasText('delta');
516
+ });
517
+
518
+ test("addon depends on an app's module via relative import", async function (assert) {
519
+ assert.strictEqual(appLibOne(), libOneViaAddon(), 'lib one works the same');
520
+ assert.strictEqual(globalThis.appLibOneLoaded, 1, 'app lib one loaded once');
521
+ });
522
+
523
+ test("addon depends on an app's module via named import", async function (assert) {
524
+ assert.strictEqual(appLibTwo(), libTwoViaAddon(), 'lib two works the same');
525
+ assert.strictEqual(globalThis.appLibTwoLoaded, 1, 'app lib two loaded once');
526
+ });
527
+ });
528
+ ` ,
529
+ } ,
530
+ } ,
531
+ } ,
532
+ } ) ;
533
+
534
+ let v1ExampleAddon = baseAddon ( ) ;
535
+ v1ExampleAddon . name = 'v1-example-addon' ;
536
+ v1ExampleAddon . mergeFiles ( {
537
+ addon : {
538
+ components : {
539
+ 'beta.js' : `
540
+ import Component from '@glimmer/component';
541
+ export default class extends Component {
542
+ message = "beta";
543
+ }
544
+ ` ,
545
+ 'beta.hbs' : `
546
+ <div class="beta">{{this.message}}</div>
547
+ <Gamma />
548
+ ` ,
549
+ 'zeta.hbs' : `
550
+ <div class="zeta">Zeta</div>
551
+ <Epsilon />
552
+ ` ,
553
+ } ,
554
+ } ,
555
+ app : {
556
+ 'v1-example-addon.js' : `
557
+ import appLibOne from './lib/app-lib-one';
558
+ import appLibTwo from 'app-template/lib/app-lib-two';
559
+ export { appLibOne, appLibTwo };
560
+ ` ,
561
+ templates : {
562
+ components : {
563
+ 'delta.hbs' : `
564
+ <div class="delta">delta</div>
565
+ ` ,
566
+ } ,
567
+ } ,
568
+ components : {
569
+ 'beta.js' : `
570
+ export { default } from 'v1-example-addon/components/beta';
571
+ ` ,
572
+ 'zeta.js' : `
573
+ export { default } from 'v1-example-addon/components/zeta';
574
+ ` ,
575
+ } ,
576
+ } ,
577
+ } ) ;
578
+ app . addDevDependency ( v1ExampleAddon ) ;
579
+ } )
580
+ . forEachScenario ( scenario => {
581
+ Qmodule ( scenario . name , function ( hooks ) {
582
+ let app : PreparedApp ;
583
+ let server : CommandWatcher ;
584
+
585
+ hooks . before ( async ( ) => {
586
+ app = await scenario . prepare ( ) ;
587
+ } ) ;
588
+
589
+ Qmodule ( 'vite dev' , function ( hooks ) {
590
+ hooks . before ( async ( ) => {
591
+ server = CommandWatcher . launch ( 'vite' , [ '--clearScreen' , 'false' , '--base' , '/sub-dir/' ] , { cwd : app . dir } ) ;
592
+ } ) ;
593
+
594
+ hooks . after ( async ( ) => {
595
+ await server ?. shutdown ( ) ;
596
+ } ) ;
597
+
598
+ test ( 'run test suite against vite dev' , async function ( assert ) {
599
+ let result = await app . execute ( 'pnpm testem --file testem-dev.js ci' ) ;
600
+ assert . equal ( result . exitCode , 0 , result . output ) ;
601
+ } ) ;
602
+ } ) ;
603
+
604
+ Qmodule ( 'vite build' , function ( hooks ) {
605
+ hooks . before ( async ( ) => {
606
+ await app . execute ( 'pnpm vite build --mode test --base /sub-dir/' ) ;
607
+ await app . execute ( 'mkdir ./sub-dir' ) ;
608
+ await app . execute ( 'mv dist/* ./sub-dir' ) ;
609
+ await app . execute ( 'mkdir ./dist/sub-dir' ) ;
610
+ await app . execute ( 'mv sub-dir/* ./dist/sub-dir' ) ;
611
+ } ) ;
612
+
613
+ test ( 'run test suite against vite dist with sub-dir' , async function ( assert ) {
614
+ let result = await app . execute ( 'ember test --path dist' ) ;
615
+ assert . equal ( result . exitCode , 0 , result . output ) ;
616
+ } ) ;
617
+ } ) ;
618
+ } ) ;
619
+ } ) ;
0 commit comments