Skip to content

Commit

Permalink
fix: fix modular ux and bugs (#1738)
Browse files Browse the repository at this point in the history
* fix: fix add bugs and ux

* Create dirty-teachers-worry.md
  • Loading branch information
benpryke authored May 19, 2022
1 parent 862728b commit bc95a70
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 108 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-teachers-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"modular-scripts": patch
---

fix: fix modular ux and bugs
Original file line number Diff line number Diff line change
Expand Up @@ -8662,6 +8662,25 @@ exports[`When working with a nested app can generate a manifest 1`] = `
"
`;

exports[`when working with a NODE_ENV app can generate a hashed js chunk in the js directory 1`] = `
"\\"use strict\\";
(globalThis.webpackChunknode_env_app =
globalThis.webpackChunknode_env_app || []).push([
[179],
{
908: () => {
console.log(\\"production\\");
},
},
(o) => {
var e;
(e = 908), o((o.s = e));
},
]);
//# sourceMappingURL=main.1c6de6d0.js.map
"
`;

exports[`when working with an app can generate a asset-manifest 1`] = `
"{
\\"files\\": {
Expand Down
7 changes: 3 additions & 4 deletions packages/modular-scripts/src/__tests__/app.esbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ afterAll(cleanup);

describe('when working with an app', () => {
beforeAll(async () => {
await modular(
'add sample-esbuild-app --unstable-type app --unstable-name sample-esbuild-app',
{ stdio: 'inherit' },
);
await modular('add sample-esbuild-app --unstable-type app', {
stdio: 'inherit',
});

await modular('build sample-esbuild-app', {
stdio: 'inherit',
Expand Down
5 changes: 1 addition & 4 deletions packages/modular-scripts/src/__tests__/app.node-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ afterAll(cleanup);

describe('when working with a NODE_ENV app', () => {
beforeAll(async () => {
await modular(
'add node-env-app --unstable-type app --unstable-name node-env-app',
{ stdio: 'inherit' },
);
await modular('add node-env-app --unstable-type app', { stdio: 'inherit' });

await fs.writeFile(
path.join(modularRoot, 'packages', 'node-env-app', 'src', 'index.ts'),
Expand Down
77 changes: 69 additions & 8 deletions packages/modular-scripts/src/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function modular(str: string, opts: Record<string, unknown> = {}) {
}

function cleanup() {
rimraf.sync(path.join(packagesPath, 'node-env-app'));
rimraf.sync(path.join(modularRoot, 'dist/node-env-app'));

rimraf.sync(path.join(packagesPath, 'sample-app'));
rimraf.sync(path.join(modularRoot, 'dist/sample-app'));

Expand All @@ -50,13 +53,74 @@ function cleanup() {
beforeAll(cleanup);
afterAll(cleanup);

describe('When working with a nested app', () => {
describe('when working with a NODE_ENV app', () => {
beforeAll(async () => {
await modular(
'add scoped/sample-app --unstable-type app --unstable-name @scoped/sample-app',
{ stdio: 'inherit' },
await modular('add node-env-app --unstable-type app', { stdio: 'inherit' });

await fs.writeFile(
path.join(modularRoot, 'packages', 'node-env-app', 'src', 'index.ts'),
`
console.log(process.env.NODE_ENV);
export {};
`,
);

await modular('build node-env-app', {
stdio: 'inherit',
});
});

it('can build a app', () => {
expect(tree(path.join(modularRoot, 'dist', 'node-env-app')))
.toMatchInlineSnapshot(`
"node-env-app
├─ asset-manifest.json #1qjm6tq
├─ favicon.ico #6pu3rg
├─ index.html #z3zac4
├─ logo192.png #1nez7vk
├─ logo512.png #1hwqvcc
├─ manifest.json #19gah8o
├─ package.json
├─ robots.txt #1sjb8b3
└─ static
└─ js
├─ main.1c6de6d0.js #1xkcjze
├─ main.1c6de6d0.js.map #1mixunf
├─ runtime-main.182069c4.js #r0hm4v
└─ runtime-main.182069c4.js.map #ul1xez"
`);
});

it('can generate a hashed js chunk in the js directory', async () => {
expect(
prettier.format(
String(
await fs.readFile(
path.join(
modularRoot,
'dist',
'node-env-app',
'static',
'js',
'main.1c6de6d0.js',
),
),
),
{
filepath: 'main.1c6de6d0.js',
},
),
).toMatchSnapshot();
});
});

describe('When working with a nested app', () => {
beforeAll(async () => {
await modular('add @scoped/sample-app --unstable-type app', {
stdio: 'inherit',
});

await modular('build @scoped/sample-app', {
stdio: 'inherit',
});
Expand Down Expand Up @@ -241,10 +305,7 @@ describe('When working with a nested app', () => {

describe('when working with an app', () => {
beforeAll(async () => {
await modular(
'add sample-app --unstable-type app --unstable-name sample-app',
{ stdio: 'inherit' },
);
await modular('add sample-app --unstable-type app', { stdio: 'inherit' });

// Let's replace the App module with something of our own
// with a test specific element we can introspect
Expand Down
31 changes: 11 additions & 20 deletions packages/modular-scripts/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,13 @@ describe('modular-scripts', () => {
beforeAll(async () => {
await cleanup();

await modular(
'add sample-view --unstable-type view --unstable-name sample-view',
{ stdio: 'inherit' },
);
await modular(
'add sample-package --unstable-type package --unstable-name sample-package',
{
stdio: 'inherit',
},
);
await modular(
'add nested/sample-nested-package --unstable-type package --unstable-name @nested/sample-package',
{
stdio: 'inherit',
},
);
await modular('add sample-view --unstable-type view', { stdio: 'inherit' });
await modular('add sample-package --unstable-type package', {
stdio: 'inherit',
});
await modular('add @nested/sample-package --unstable-type package', {
stdio: 'inherit',
});

await fs.copyFile(
path.join(__dirname, 'TestView.test-tsx'),
Expand Down Expand Up @@ -122,9 +113,9 @@ describe('modular-scripts', () => {
});

it('can add a nested package', () => {
expect(tree(path.join(packagesPath, 'nested/sample-nested-package')))
expect(tree(path.join(packagesPath, 'nested/sample-package')))
.toMatchInlineSnapshot(`
"sample-nested-package
"sample-package
├─ package.json
└─ src
├─ __tests__
Expand Down Expand Up @@ -312,7 +303,7 @@ describe('modular-scripts', () => {

it('can execute tests', async () => {
const output = await modular(
'test sample-package sample-view sample-nested-package --watchAll false',
'test sample-package sample-view @nested/sample-package --watchAll false',
{
all: true,
reject: false,
Expand All @@ -337,7 +328,7 @@ describe('modular-scripts', () => {
'PASS test packages/sample-package/src/__tests__/index.test.ts',
);
expect(cleanedOutput).toContain(
'PASS test packages/nested/sample-nested-package/src/__tests__/index.test.ts',
'PASS test packages/nested/sample-package/src/__tests__/index.test.ts',
);
});

Expand Down
Loading

0 comments on commit bc95a70

Please sign in to comment.