From 49d1e59a99457496e8c2b923eacfefb786611dd7 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Sun, 22 Sep 2024 13:49:13 +0000 Subject: [PATCH] fix tests --- .github/workflows/ci.yml | 17 ++++++++++------- src/babel-plugin.js | 15 ++++++--------- tests-babel/transform.test.js | 34 +++++++++++++++++----------------- tests/integration/gjs-test.gjs | 2 +- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ea677d..713e7a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,5 @@ -name: CI +name: CI2 + on: push: @@ -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! @@ -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: @@ -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: @@ -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: diff --git a/src/babel-plugin.js b/src/babel-plugin.js index 8b2419c..60bbc3e 100644 --- a/src/babel-plugin.js +++ b/src/babel-plugin.js @@ -1,4 +1,4 @@ -const { basename, extname } = require('path'); +const { basename, extname, dirname } = require('path'); module.exports = function addTOCNames({ types: t }) { return { @@ -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 ( diff --git a/tests-babel/transform.test.js b/tests-babel/transform.test.js index e0872ef..5820685 100644 --- a/tests-babel/transform.test.js +++ b/tests-babel/transform.test.js @@ -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', plugins: [ [ plugin, @@ -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 @@ -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"; @@ -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, { @@ -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, { @@ -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"));" `); }); }); diff --git a/tests/integration/gjs-test.gjs b/tests/integration/gjs-test.gjs index 96020d0..f944915 100644 --- a/tests/integration/gjs-test.gjs +++ b/tests/integration/gjs-test.gjs @@ -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); });