Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Sep 22, 2024
1 parent c043fa5 commit 49d1e59
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: CI
name: CI2


on:
push:
Expand Down Expand Up @@ -35,6 +36,8 @@ jobs:
node-version: 16.x
- name: ember test
run: pnpm test:ember
- name: babel test
run: pnpm test:babel

# For example: don't bother with *other* Node version tests unless the base
# case passes!
Expand All @@ -53,8 +56,8 @@ jobs:
- uses: wyvox/action-setup-pnpm@v3
with:
node-version: ${{ matrix.node-version }}
- name: tests
run: pnpm test
- name: ember test
run: pnpm test:ember

# macOS and Windows can run after we clear ubuntu (don't bother otherwise)
test-other-os:
Expand All @@ -72,8 +75,8 @@ jobs:
- uses: wyvox/action-setup-pnpm@v3
with:
node-version: 16.x
- name: test
run: pnpm test
- name: ember test
run: pnpm test:ember

# floating deps likewise are only gated on ubuntu tests passing
floating-dependencies:
Expand All @@ -87,8 +90,8 @@ jobs:
- uses: wyvox/action-setup-pnpm@v3
with:
node-version: 16.x
- name: test
run: pnpm test
- name: ember test
run: pnpm test:ember

# as are other compatibility scenarios
try-scenarios:
Expand Down
15 changes: 6 additions & 9 deletions src/babel-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { basename, extname } = require('path');
const { basename, extname, dirname } = require('path');

module.exports = function addTOCNames({ types: t }) {
return {
Expand All @@ -20,20 +20,17 @@ module.exports = function addTOCNames({ types: t }) {
let params = path.node.arguments;
let assignment = path.parentPath.parentPath.node;
let filename = state.filename
.replace(state.opts.root, '')
.replace(dirname(state.opts.root), '')
.replace(/\\/g, '/')
.split('/')
.slice(2)
.join('/')
.split('/rewritten-app/')
.slice(-1)[0]
.replace('/node_modules/.embroider/rewritten-app', '');
let shortName = filename
.replace(/template.hbs$/, '')
.replace(/component\.(js|ts)$/, '')
.replace(/index\.(js|ts)$/, '')
.replace(/\/$/, '');
let rootName = basename(filename).slice(
let rootName = basename(shortName).slice(
0,
-extname(state.filename).length || undefined, // undefined -> same as slice(0)
-extname(shortName).length || undefined, // undefined -> same as slice(0)
);
let assignmentName = t.identifier('undefined');
if (
Expand Down
34 changes: 17 additions & 17 deletions tests-babel/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('convert templates', () => {
const preTransformed = p.process(code);

const opts = {
filename: '/tmp/path/my-app/node_modules/rewritten-app/components/a.hbs',
filename: '/tmp/path/my-app/node_modules/.embroider/rewritten-app/components/a.hbs',

Check failure on line 16 in tests-babel/transform.test.js

View workflow job for this annotation

GitHub Actions / Linting

Insert `⏎·······`
plugins: [
[
plugin,
Expand Down Expand Up @@ -47,11 +47,11 @@ describe('convert templates', () => {
some content
*/
{
"id": "xn207nfA",
"id": "R0DE3v6/",
"block": "[[[1,\\"some content\\"]],[],false,[]]",
"moduleName": "/rewritten-app/a.hbs",
"moduleName": "/tmp/path/my-app/node_modules/.embroider/rewritten-app/components/a.hbs",
"isStrictMode": true
}), templateOnly("a.hbs", "a:toc"));"
}), templateOnly("/my-app/components/a.hbs", "a:toc"));"
`);

// classic receives relative paths
Expand All @@ -68,16 +68,16 @@ describe('convert templates', () => {
some content
*/
{
"id": "xn207nfA",
"id": "RkleawBf",
"block": "[[[1,\\"some content\\"]],[],false,[]]",
"moduleName": "/rewritten-app/a.hbs",
"moduleName": "/my-app/components/a.hbs",
"isStrictMode": true
}), templateOnly("a.hbs", "a:toc"));"
}), templateOnly("/my-app/components/a.hbs", "a:toc"));"
`);

result = babel.transform(preTransformed, {
...opts,
filename: '/my-app/components/a/template.hbs',
filename: ' /my-app/components/a/template.hbs',
});
expect(result.code).toMatchInlineSnapshot(`
"import { setComponentTemplate } from "@ember/component";
Expand All @@ -88,11 +88,11 @@ describe('convert templates', () => {
some content
*/
{
"id": "xn207nfA",
"id": "iPmNUq2D",
"block": "[[[1,\\"some content\\"]],[],false,[]]",
"moduleName": "/rewritten-app/a.hbs",
"moduleName": "/Users/patrickpircher/IdeaProjects/ember-template-imports/ /my-app/components/a/template.hbs",
"isStrictMode": true
}), templateOnly("a.hbs", "a:toc"));"
}), templateOnly("/Users/patrickpircher/IdeaProjects/ember-template-imports/ /my-app/components/a/template.hbs", "a:toc"));"
`);

result = babel.transform(preTransformed, {
Expand All @@ -108,11 +108,11 @@ describe('convert templates', () => {
some content
*/
{
"id": "xn207nfA",
"id": "g+fScEK3",
"block": "[[[1,\\"some content\\"]],[],false,[]]",
"moduleName": "/rewritten-app/a.hbs",
"moduleName": "/my-app/components/a/component.gjs",
"isStrictMode": true
}), templateOnly("a.hbs", "a:toc"));"
}), templateOnly("/my-app/components/a/component.gjs", "component:toc"));"
`);

result = babel.transform(preTransformed, {
Expand All @@ -128,11 +128,11 @@ describe('convert templates', () => {
some content
*/
{
"id": "xn207nfA",
"id": "fbPvCNHK",
"block": "[[[1,\\"some content\\"]],[],false,[]]",
"moduleName": "/rewritten-app/a.hbs",
"moduleName": "/my-app/components/a/index.gjs",
"isStrictMode": true
}), templateOnly("a.hbs", "a:toc"));"
}), templateOnly("/my-app/components/a/index.gjs", "index:toc"));"
`);
});
});
2 changes: 1 addition & 1 deletion tests/integration/gjs-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module('tests/integration/components/gjs', function (hooks) {

assert.equal(this.element.textContent.trim(), 'Hello, world!');
assert.equal(Foo.name, 'gjs-test:Foo');
assert.equal(Foo.moduleName, 'tests/integration/gjs-test.js');
assert.equal(Foo.moduleName, 'dummy/tests/integration/gjs-test.js');
console.log(Foo);
});

Expand Down

0 comments on commit 49d1e59

Please sign in to comment.