From 12e5c09081537ac61568dbd6a5a77cde2be97b7a Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Wed, 6 Dec 2023 19:38:25 +0100 Subject: [PATCH] Add tests for asset loading and query params --- test-scenarios/static-import-test.ts | 48 ++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/test-scenarios/static-import-test.ts b/test-scenarios/static-import-test.ts index fb0f6930..3f1b81b3 100644 --- a/test-scenarios/static-import-test.ts +++ b/test-scenarios/static-import-test.ts @@ -42,8 +42,19 @@ function staticImportTest(project: Project) { 'original-package' ], allowAppImports: [ - 'lib/**' - ] + 'lib/**', + 'assets/*.specialfile', + ], + webpack: { + module: { + rules: [ + { + test: /\.specialfile/, + use: 'specialfile-loader', + }, + ], + }, + }, } }); return app.toTree(); @@ -132,6 +143,9 @@ function staticImportTest(project: Project) { `, }, }, + assets: { + 'test.specialfile': 'This is just plain text.', + }, }, tests: { helpers: { @@ -200,6 +214,8 @@ function staticImportTest(project: Project) { dont_find_me_4, secret_string_7 } from '../../lib/example2'; + import testAsset from '@ef4/app-template/assets/test.specialfile'; + import { query as testAssetQuery } from '@ef4/app-template/assets/test.specialfile?foo=bar'; import Service from '@ember/service'; import example6Direct, { dont_find_me } from '@ef4/app-template/utils/example6'; import example7Direct, { secret_string } from '@ef4/app-template/utils/example7'; @@ -280,6 +296,20 @@ function staticImportTest(project: Project) { 'should not have example3 in loader' ); }); + test('it can import assets handled by loader', function (assert) { + assert.strictEqual( + testAsset, + 'This is just plain text.', + 'Content loaded from customloader can be imported' + ); + }); + test('it can import assets that have query params', function (assert) { + assert.strictEqual( + testAssetQuery, + '?foo=bar', + 'query params are correctly handled' + ); + }); }); `, }, @@ -312,6 +342,20 @@ function staticImportTest(project: Project) { }`, }, }); + + project.addDevDependency('specialfile-loader', { + files: { + 'index.js': ` + export default function customLoader(source) { + return \`export const query = \${JSON.stringify(this.resourceQuery)}; + export default \${JSON.stringify(source)}\`; + } + `, + 'package.json': JSON.stringify({ + type: 'module', + }), + }, + }); } let scenarios = appScenarios.map('static-import', project => {