Skip to content

Prove that ember-scoped-css doesn't change class names as you move classic -> embroider -> etc #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
24 changes: 20 additions & 4 deletions ember-scoped-css/src/build/babel-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,27 @@ export default (env, options, workingDirectory) => {

let cssPath = cssPathFor(fileName);

if (existsSync(cssPath)) {
let baseCSS = nodePath.basename(cssPath);

state.importUtil.importForSideEffect(`./${baseCSS}`);
if (!existsSync(cssPath)) {
// check if we have an extraneous folder path
// this can happen because plugins have tried using
// the module path instead of the real path on disk.
// it's tricky to support both when there are no standards
// around managing these paths.
// But also, in normal projects, they are not different paths.
let [, ...parts] = cssPath.split('/');

cssPath = ['app', ...parts].join('/');

if (!existsSync(cssPath)) {
// there is no css path
// we don't want to add an import of the CSS file doesn't exist
return;
}
}

let baseCSS = nodePath.basename(cssPath);

state.importUtil.importForSideEffect(`./${baseCSS}`);
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
let expected = 'ea418816b';

it('matches the module path', () => {
let postfix = hashFromModulePath(`embroider-app/${file}`);
let postfix = hashFromModulePath(`test-app/${file}`);

expect(postfix).to.equal(expected);

Check failure on line 17 in ember-scoped-css/src/lib/path/hash-from-absolute-path.test.ts

View workflow job for this annotation

GitHub Actions / Test ember-scoped-css

src/lib/path/hash-from-absolute-path.test.ts > hashFromAbsolutePath > the module: "embroider-app/templates/application" > matches the module path

AssertionError: expected 'e54ae2a87' to equal 'ea418816b' - Expected + Received - ea418816b + e54ae2a87 ❯ src/lib/path/hash-from-absolute-path.test.ts:17:26
});

it('works with rewritten app', () => {
Expand All @@ -26,14 +26,14 @@

let postfix = hashFromAbsolutePath(filePath);

expect(postfix).to.equal(expected);

Check failure on line 29 in ember-scoped-css/src/lib/path/hash-from-absolute-path.test.ts

View workflow job for this annotation

GitHub Actions / Test ember-scoped-css

src/lib/path/hash-from-absolute-path.test.ts > hashFromAbsolutePath > the module: "embroider-app/templates/application" > works with rewritten app

AssertionError: expected 'e54ae2a87' to equal 'ea418816b' - Expected + Received - ea418816b + e54ae2a87 ❯ src/lib/path/hash-from-absolute-path.test.ts:29:26
});

it('works with direct path', () => {
let filePath = path.join(paths.embroiderApp, 'app', file);
let postfix = hashFromAbsolutePath(filePath);

expect(postfix).to.equal(expected);

Check failure on line 36 in ember-scoped-css/src/lib/path/hash-from-absolute-path.test.ts

View workflow job for this annotation

GitHub Actions / Test ember-scoped-css

src/lib/path/hash-from-absolute-path.test.ts > hashFromAbsolutePath > the module: "embroider-app/templates/application" > works with direct path

AssertionError: expected 'e54ae2a87' to equal 'ea418816b' - Expected + Received - ea418816b + e54ae2a87 ❯ src/lib/path/hash-from-absolute-path.test.ts:36:26
});
});
});
6 changes: 3 additions & 3 deletions ember-scoped-css/src/lib/path/utils.appPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ describe('appPath()', () => {
);
let result = appPath(file);

expect(result).to.equal('embroider-app/templates/application');
expect(result).to.equal('test-app/templates/application');
});

it('handles extraneous /app/', () => {
let file = path.join(paths.embroiderApp, 'app', 'templates/application');
let result = appPath(file);

expect(result).to.equal('embroider-app/templates/application');
expect(result).to.equal('test-app/templates/application');
});

it('handles psuedo module', () => {
let file = path.join(paths.embroiderApp, 'templates/application');
let result = appPath(file);

expect(result).to.equal('embroider-app/templates/application');
expect(result).to.equal('test-app/templates/application');
});
});
30 changes: 30 additions & 0 deletions sync-test-apps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import path from 'node:path';
import fs from 'node:fs/promises';

const cwd = process.cwd();
const source = 'test-apps/classic-app';
const sourceComponents = path.join(source, 'app/components');
const sourceTests = path.join(source, 'tests/shared-scenarios');

const otherApps = ['embroider-app', 'pods-classic-app', 'pods-embroider-app'];

async function sync(source, destination) {
let target = path.join('../../', source).replace('/test-apps/', '/');

console.log(target);

await fs.rm(destination, { force: true, recursive: true });
await fs.symlink(target, destination);
}

for (let app of otherApps) {
await sync(
sourceComponents,
path.join(cwd, 'test-apps', app, 'app/components'),
);

await sync(
sourceTests,
path.join(cwd, 'test-apps', app, 'tests/shared-scenarios'),
);
}
2 changes: 1 addition & 1 deletion test-apps/classic-app/app/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Application from '@ember/application';

import config from 'classic-app/config/environment';
import loadInitializers from 'ember-load-initializers';
import Resolver from 'ember-resolver';
import config from 'test-app/config/environment';

export default class App extends Application {
modulePrefix = config.modulePrefix;
Expand Down
8 changes: 2 additions & 6 deletions test-apps/classic-app/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
{{content-for "head"}}

<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css" />
<link
integrity=""
rel="stylesheet"
href="{{rootURL}}assets/classic-app.css"
/>
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/test-app.css" />

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/classic-app.js"></script>
<script src="{{rootURL}}assets/test-app.js"></script>

{{content-for "body-footer"}}
</body>
Expand Down
2 changes: 1 addition & 1 deletion test-apps/classic-app/app/router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EmberRouter from '@ember/routing/router';

import config from 'classic-app/config/environment';
import config from 'test-app/config/environment';

export default class Router extends EmberRouter {
location = config.locationType;
Expand Down
2 changes: 1 addition & 1 deletion test-apps/classic-app/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = function (environment) {
const ENV = {
modulePrefix: 'classic-app',
modulePrefix: 'test-app',
environment,
rootURL: '/',
locationType: 'history',
Expand Down
9 changes: 8 additions & 1 deletion test-apps/classic-app/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
// All our test-apps must have the same name
// so that we can ensure that moving between configurations
// causes no string-comparison headaches.
name: 'test-app',
// Add options here
cssModules: {
extension: 'module.css',
},
autoImport: {
allowAppImports: ['*.css'],
},
'ember-cli-babel': {
enableTypeScriptTransform: true,
},
'ember-scoped-css': {
layerName: 'classic-app-layer',
layerName: 'test-app',
},
});

Expand Down
6 changes: 3 additions & 3 deletions test-apps/classic-app/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
{{content-for "head"}} {{content-for "test-head"}}

<link rel="stylesheet" href="{{rootURL}}assets/vendor.css" />
<link rel="stylesheet" href="{{rootURL}}assets/classic-app.css" />
<link rel="stylesheet" href="{{rootURL}}assets/test-support.css" />
<link rel="stylesheet" href="{{rootURL}}assets/test-app.css" />

{{content-for "head-footer"}} {{content-for "test-head-footer"}}
</head>

<body>
{{content-for "body"}} {{content-for "test-body"}}

Expand All @@ -27,7 +27,7 @@
<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
<script src="{{rootURL}}assets/classic-app.js"></script>
<script src="{{rootURL}}assets/test-app.js"></script>
<script src="{{rootURL}}assets/tests.js"></script>

{{content-for "body-footer"}} {{content-for "test-body-footer"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

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

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

Expand All @@ -16,8 +16,8 @@ module('[In App] at-class-ts', function(hooks) {
</template>
);

assert.dom('p').hasClass('text-color_ed46c3a30');
assert.dom('p').hasClass(scopedClass('text-color', 'classic-app/components/in-app/at-class-ts/calls-has-at-class'));
assert.dom('p').hasClass('text-color_e859f8885');
assert.dom('p').hasClass(scopedClass('text-color', 'test-app/components/in-app/at-class-ts/calls-has-at-class'));
assert.dom('p').hasStyle({ color: 'rgb(51, 51, 119)' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import Basic from 'classic-app/components/in-app/basic';
import Basic from 'test-app/components/in-app/basic';

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

Expand All @@ -17,7 +17,7 @@ module('[In App] basic', function(hooks) {
);

assert.dom('div').hasClass('has-a-style_e8d85123f');
assert.dom('div').hasClass(scopedClass('has-a-style', 'classic-app/components/in-app/basic'));
assert.dom('div').hasClass(scopedClass('has-a-style', 'test-app/components/in-app/basic'));
assert.dom('div').hasStyle({ color: 'rgb(0, 100, 50)', fontWeight: '700' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import ComponentAtClass from 'classic-app/components/component-at-class';
import ComponentAtClass from 'test-app/components/component-at-class';

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

Expand All @@ -20,7 +20,7 @@ module('[In App] @class', function (hooks) {
assert
.dom('p')
.hasClass(
scopedClass('text-color', 'classic-app/components/component-at-class')
scopedClass('text-color', 'test-app/components/component-at-class')
);
assert.dom('p').hasStyle({ color: 'rgb(0, 0, 255)' });
});
Expand All @@ -33,7 +33,7 @@ module('[In App] @class', function (hooks) {
assert
.dom('p')
.hasClass(
scopedClass('text-color', 'classic-app/components/component-at-class')
scopedClass('text-color', 'test-app/components/component-at-class')
);
assert.dom('p').hasStyle({ color: 'rgb(0, 0, 255)' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setupRenderingTest } from 'ember-qunit';

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

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

test('it has scoped class', async function (assert) {
Expand All @@ -15,6 +15,6 @@ module('[In App] header', function (hooks) {
assert.dom('h1').hasStyle({ color: 'rgb(255, 0, 0)' });
assert
.dom('h1')
.hasClass(scopedClass('test-header', 'classic-app/components/header'));
.hasClass(scopedClass('test-header', 'test-app/components/header'));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { render, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import SubExpression from 'classic-app/components/subexpression';
import { cell } from 'ember-resources';
import SubExpression from 'test-app/components/subexpression';

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

Expand All @@ -27,7 +27,7 @@ module('[In App] subexpression', function (hooks) {
assert
.dom('div')
.hasClass(
scopedClass('a-local-class', 'classic-app/components/subexpression')
scopedClass('a-local-class', 'test-app/components/subexpression')
);
assert.dom('div').hasStyle({ color: 'rgb(0, 0, 255)' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ module('[In App] template-only', function (hooks) {

assert
.dom('div')
.hasClass(
scopedClass('some-class', 'classic-app/components/template-only'),
);
.hasClass(scopedClass('some-class', 'test-app/components/template-only'));
assert.dom('div').hasStyle({ color: 'rgb(0, 0, 255)' });
});
});
4 changes: 2 additions & 2 deletions test-apps/classic-app/tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as QUnit from 'qunit';
import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';

import Application from 'classic-app/app';
import config from 'classic-app/config/environment';
import Application from 'test-app/app';
import config from 'test-app/config/environment';

setApplication(Application.create(config.APP));

Expand Down
2 changes: 1 addition & 1 deletion test-apps/embroider-app/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Application from '@ember/application';

import loadInitializers from 'ember-load-initializers';
import Resolver from 'ember-resolver';
import config from 'embroider-app/config/environment';
import config from 'test-app/config/environment';

export default class App extends Application {
modulePrefix = config.modulePrefix;
Expand Down
1 change: 1 addition & 0 deletions test-apps/embroider-app/app/components
Empty file.
19 changes: 0 additions & 19 deletions test-apps/embroider-app/app/components/forth.css

This file was deleted.

10 changes: 0 additions & 10 deletions test-apps/embroider-app/app/components/forth.gjs

This file was deleted.

22 changes: 0 additions & 22 deletions test-apps/embroider-app/app/components/my-component.css

This file was deleted.

9 changes: 0 additions & 9 deletions test-apps/embroider-app/app/components/my-component.hbs

This file was deleted.

Loading
Loading