Skip to content

Commit

Permalink
Merge pull request #257 from soxhub/additional-gts-test
Browse files Browse the repository at this point in the history
Fix issue with gts detection when using embroider-webpack's rewritten-app.
  • Loading branch information
NullVoxPopuli authored Jul 19, 2024
2 parents febc6a3 + f4e0f84 commit 1398d85
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 21 deletions.
5 changes: 2 additions & 3 deletions ember-scoped-css/src/build/app-css-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ export default async function (code) {

const hbsPath = cssPath.replace('.css', '.hbs');
const gjsPath = cssPath.replace('.css', '.js');
const hbsExists = existsSync(hbsPath);
const gjsExists = existsSync(gjsPath);
const gtsPath = cssPath.replace('.css', '.ts');

if (hbsExists || gjsExists) {
if (existsSync(gjsPath) || existsSync(gtsPath) || existsSync(hbsPath)) {
const postfix = hashFrom(cssPath);
const rewrittenCss = rewriteCss(
code,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.text-color {
color: #337 !important;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { scopedClass } from 'ember-scoped-css';

import HasAtClass from './has-at-class';

<template>
<HasAtClass @class={{scopedClass "text-color"}} />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p class={{@class}} ...attributes>some text</p>
</template>
7 changes: 7 additions & 0 deletions test-apps/embroider-app/app/components/in-app/basic.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.has-a-style {
color: rgb(0, 100, 50);
}

div {
font-weight: bold;
}
3 changes: 3 additions & 0 deletions test-apps/embroider-app/app/components/in-app/basic.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div class="has-a-style">text here</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p class={{scoped-class "foo"}}>No CSS here!</p>
1 change: 1 addition & 0 deletions test-apps/embroider-app/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = async function (defaults) {
packagerOptions: {
// css loaders for live reloading css
webpackConfig: {
devtool: 'source-map',
module: {
rules: [
// css loaders for production
Expand Down
3 changes: 3 additions & 0 deletions test-apps/embroider-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@nullvoxpopuli/eslint-configs": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"broccoli-asset-rev": "^3.0.0",
"concurrently": "^8.2.2",
"copy-webpack-plugin": "^11.0.0",
Expand Down Expand Up @@ -72,6 +74,7 @@
"qunit": "^2.20.0",
"qunit-dom": "^3.0.0",
"tracked-built-ins": "^3.1.0",
"typescript": "^5.5.3",
"v2-addon": "workspace:*",
"webpack": "^5.91.0"
},
Expand Down
212 changes: 194 additions & 18 deletions test-apps/embroider-app/pnpm-lock.yaml

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions test-apps/embroider-app/tests/integration/in-app/at-class-test.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import CallsAtHasClass from 'embroider-app/components/in-app/at-class-ts/calls-has-at-class';

import { scopedClass } from 'ember-scoped-css/test-support';

module('[In App] at-class-ts', function(hooks) {
setupRenderingTest(hooks);

test('calls component with @class', async function(assert) {
await render(
<template>
<CallsAtHasClass />
</template>
);

assert.dom('p').hasClass(scopedClass('text-color', 'embroider-app/components/in-app/at-class-ts/calls-has-at-class'));
assert.dom('p').hasStyle({ color: 'rgb(51, 51, 119)' });
});
});
22 changes: 22 additions & 0 deletions test-apps/embroider-app/tests/integration/in-app/basic-test.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import Basic from 'embroider-app/components/in-app/basic';

import { scopedClass } from 'ember-scoped-css/test-support';

module('[In App] basic', function(hooks) {
setupRenderingTest(hooks);

test('has a style on an element', async function(assert) {
await render(
<template>
<Basic />
</template>
);

assert.dom('div').hasClass(scopedClass('has-a-style', 'embroider-app/components/in-app/basic'));
assert.dom('div').hasStyle({ color: 'rgb(0, 100, 50)', fontWeight: '700' });
});
});

0 comments on commit 1398d85

Please sign in to comment.