Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
fix(one-app-server-bundler): remove excess (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker authored Mar 15, 2024
1 parent d3b036d commit fe11092
Show file tree
Hide file tree
Showing 27 changed files with 220 additions and 1,180 deletions.
77 changes: 0 additions & 77 deletions packages/one-app-server-bundler/__mocks__/fs.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/one-app-server-bundler/__mocks__/node:fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ const fs = {
files[filePath] = content;
}),

rmdirSync: jest.fn((dirPath) => {
if (!files[dirPath]) {
throw new Error(`Couldn't delete dir ${dirPath}`);
rmSync: jest.fn((path, opts = {}) => {
if (!files[path] && !opts.force) {
throw new Error(`Couldn't delete file/dir ${path}`);
}
delete files[dirPath];
delete files[path];
}),

mkdirSync: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports['serve-module adds to the existing module map 1'] = `
exports[`serve-module adds to the existing module map 1`] = `
"{
\\"key\\": \\"--- omitted for development ---\\",
\\"modules\\": {
Expand Down Expand Up @@ -36,7 +36,7 @@ exports['serve-module adds to the existing module map 1'] = `
}"
`;

exports['serve-module adds to the existing module map without legacy when disableDevelopmentLegacyBundle is true 1'] = `
exports[`serve-module adds to the existing module map without legacy when legacy bundle does not exist 1`] = `
"{
\\"key\\": \\"--- omitted for development ---\\",
\\"modules\\": {
Expand Down Expand Up @@ -64,7 +64,7 @@ exports['serve-module adds to the existing module map without legacy when disabl
}"
`;

exports['serve-module creates a module map when one does not exist 1'] = `
exports[`serve-module creates a module map when one does not exist 1`] = `
"{
\\"key\\": \\"not-used-in-development\\",
\\"modules\\": {
Expand All @@ -86,4 +86,4 @@ exports['serve-module creates a module map when one does not exist 1'] = `
}"
`;

exports['serve-module should throw if the module doesn\'t have a version 1'] = '"No versioned bundles exist for module my-module-name"';
exports[`serve-module should throw if the module doesn't have a version 1`] = `"No versioned bundles exist for module my-module-name"`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ testing `on import` functionality needs 'require' in every tests */
let fs = require('node:fs');

jest.mock('node:fs');
jest.mock('yargs', () => ({
argv: { _: ['my-module-name'] },
jest.mock('node:util', () => ({
parseArgs: jest.fn(() => ({ positionals: ['my-module-name'] })),
}));

describe('drop-module', () => {
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('drop-module', () => {
expect(fs._.getFiles()).toHaveProperty('/mocked/static/modules/my-module-name');
require('../../bin/drop-module');

expect(fs.rmdirSync).toHaveBeenCalledWith('/mocked/static/modules/my-module-name');
expect(fs.rmSync).toHaveBeenCalledWith('/mocked/static/modules/my-module-name', { recursive: true, force: true });
expect(fs._.getFiles()).not.toHaveProperty('/mocked/static/modules/my-module-name');
});

Expand Down
22 changes: 7 additions & 15 deletions packages/one-app-server-bundler/__tests__/bin/serve-module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,18 @@
/* eslint-disable global-require --
testing `on import` functionality needs 'require' in every tests */

let fs = require('fs');
let fs = require('node:fs');

let rimraf;

jest.mock('fs');
jest.mock('../../utils/getConfigOptions', () => jest.fn(() => ({ disableDevelopmentLegacyBundle: false })));
jest.mock('node:fs');

const setup = (modulePath) => {
jest.resetModules();
jest.clearAllMocks();
jest.doMock('yargs', () => ({
argv: { _: [modulePath] },
}));
jest.doMock('rimraf', () => ({
sync: jest.fn(),
jest.doMock('node:util', () => ({
parseArgs: jest.fn(() => ({ positionals: [modulePath] })),
}));

fs = require('fs');
rimraf = require('rimraf');
fs = require('node:fs');
};

describe('serve-module', () => {
Expand Down Expand Up @@ -78,7 +71,7 @@ describe('serve-module', () => {
'/mocked/static/modules/my-module-name/1.0.0': {},
});
require('../../bin/serve-module');
expect(rimraf.sync).toHaveBeenCalledWith('/mocked/static/modules/my-module-name');
expect(fs.rmSync).toHaveBeenCalledWith('/mocked/static/modules/my-module-name', { recursive: true, force: true });
});

it('should remove an existing symlink and create a new one', () => {
Expand Down Expand Up @@ -159,9 +152,8 @@ describe('serve-module', () => {
expect(fs._.getFiles()['/mocked/static/module-map.json']).toMatchSnapshot();
});

it('adds to the existing module map without legacy when disableDevelopmentLegacyBundle is true', () => {
it('adds to the existing module map without legacy when legacy bundle does not exist', () => {
process.env.NODE_ENV = 'development';
jest.mock('../../utils/getConfigOptions', () => jest.fn(() => ({ disableDevelopmentLegacyBundle: true })));
fs._.setFiles({
'../my-module-name/package.json': JSON.stringify({ name: 'my-module-name', version: '1.0.0' }),
'/mocked/static/module-map.json': JSON.stringify({
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/
const crypto = require('crypto');
const crypto = require('node:crypto');

const createHashSpy = jest.spyOn(crypto, 'createHash');

Expand Down
Loading

0 comments on commit fe11092

Please sign in to comment.