Exemple #1
0
		beforeEach(function(){
			if (get_boot_project_counter === 0){
				mock({ '/opt/Bela/startup_env': 'ACTIVE=1\nPROJECT=test_project' });
			} else if (get_boot_project_counter === 1){
				mock({ '/opt/Bela/startup_env': 'ACTIVE=0\nPROJECT=test_project' });
			} else if (get_boot_project_counter === 2){
				mock({});
			}
			get_boot_project_counter += 1;
		});
Exemple #2
0
function createMockFileSystem() {
  mockFs({
    '/node_modules/@angular': loadAngularPackages(),
    '/node_modules/rxjs': loadDirectory(resolveNpmTreeArtifact('rxjs', 'index.js')),
    '/node_modules/tslib': loadDirectory(resolveNpmTreeArtifact('tslib', 'tslib.js')),
    '/node_modules/test-package': {
      'package.json': '{"name": "test-package", "es2015": "./index.js", "typings": "./index.d.ts"}',
      // no metadata.json file so not compiled by Angular.
      'index.js':
          'import {AppModule} from "@angular/common"; export class MyApp extends AppModule {};',
      'index.d.ts':
          'import {AppModule} from "@angular/common"; export declare class MyApp extends AppModule;',
    },
    '/dist/local-package': {
      'package.json':
          '{"name": "local-package", "es2015": "./index.js", "typings": "./index.d.ts"}',
      'index.metadata.json': 'DUMMY DATA',
      'index.js': `
          import {Component} from '@angular/core';
          export class AppComponent {};
          AppComponent.decorators = [
            { type: Component, args: [{selector: 'app', template: '<h2>Hello</h2>'}] }
          ];`,
      'index.d.ts': `
          export declare class AppComponent {};`,
    },
  });
}
    it("displays versions skews correctly for hidden app roots", () => {
      mock({
        "test/fixtures/hidden-app-roots": fixtureDirs["test/fixtures/hidden-app-roots"],
      });

      return hiddenAppRootsInstance.template.text()
        .then((textStr) => {
          expect(textStr).to.eql(`
inspectpack --action=versions
=============================

## Summary
* Packages with skews:      1
* Total resolved versions:  2
* Total installed packages: 2
* Total depended packages:  2
* Total bundled files:      3

## \`bundle.js\`
* foo
  * 1.1.1
    * ~/foo
      * Num deps: 1, files: 1
      * package1@1.1.1 -> foo@^1.0.0
  * 3.3.3
    * ~/different-foo/~/foo
      * Num deps: 1, files: 2
      * package1@1.1.1 -> different-foo@^1.0.1 -> foo@^3.0.1
          `.trim());
        });
    });
      it("errors for unset name@version for non-root level", () => {
        mock({
          "test/fixtures/duplicates-cjs": {
            "node_modules": {
              foo: {
                "package.json": JSON.stringify({
                  name: "foo",
                }),
              },
            },
            "package.json": JSON.stringify({
              dependencies: {
                "different-foo": "^1.0.1",
                "flattened-foo": "^1.1.0",
                "foo": "^1.0.0",
                "uses-foo": "^1.0.9",
              },
              name: "duplicates-cjs",
              version: "1.2.3",
            }),
          },
        });

        return dupsCjsInstance.getData()
          .then(() => {
            throw new Error("test should throw");
          })
          .catch((err) => {
            expect(err).to.have.property("message").that.contains("package without version");
          });
      });
      it("permissively handles root package.json with deps and empty node_modules", () => {
        mock({
          "test/fixtures/duplicates-cjs": {
            "node_modules": {},
            "package.json": JSON.stringify({
              dependencies: {
                "different-foo": "^1.0.1",
                "flattened-foo": "^1.1.0",
                "foo": "^1.0.0",
                "uses-foo": "^1.0.9",
              },
              name: "duplicates-cjs",
              version: "1.2.3",
            }),
          },
        });

        return dupsCjsInstance.getData()
          .then((data) => {
            expect(data).to.eql(merge(BASE_DUPS_CJS_DATA, {
              assets: {
                "bundle.js": {
                  meta: EMPTY_VERSIONS_META,
                  packages: {},
                },
              },
            }));
          });
      });
    it("handles simple cases", () => {
      mock({
        "my-app": {
          "package.json": JSON.stringify({
            name: "my-app",
          }, null, 2),
        },
      });

      return _packageRoots([
        {
          identifier: resolve("my-app/src/baz/index.js"),
          isNodeModules: false,
        },
        {
          identifier: resolve("my-app/node_modules/foo/index.js"),
          isNodeModules: true,
        },
        {
          identifier: resolve("my-app/node_modules/foo/node_modules/bug/bug.js"),
          isNodeModules: true,
        },
      ]).then((pkgRoots) => {
        expect(pkgRoots).to.eql([
          resolve("my-app"),
        ]);
      });
    });
 it('should handle searching up the home directory', () => {
   mockFs({
     [`${homedir}/.angular-cli.json`]: 'foo'
   });
   const result = getProjectDetails();
   expect(result).toEqual(null);
 });
        it("errors on bad JSON", () => {
          mock({
            "package.json": "THIS_IS_NOT_JSON",
          });

          const cache = useCache ? {} : undefined;
          return Promise.all([
            readPackage("./package.json", cache),
            readPackage("./package.json", cache),
            readPackage("./NOT_FOUND/package.json", cache),
            readPackage("./package.json", cache),
          ])
            .then(() => {
              throw new Error("Should not reach then");
            })
            .catch((err) => {
              expect(err)
                .to.be.an.instanceOf(SyntaxError).and
                .to.have.property("message").that.contains("Unexpected token");

              // **Potentially brittle**: Because we invoke all in parallel, we
              // should have cache populated _first_ before any error strikes.
              //
              // **Note**: can remove this assert if it ends up being flaky.
              expect(_files.readJson).to.have.callCount(useCache ? 2 : 4);
            });
        });
Exemple #9
0
 before(() => mockFS({
   migrations: {
     '1.test.sql': 'CREATE TABLE a (a INTEGER);\n---\nDROP TABLE a;\n',
     '1.test.up.sql': 'CREATE TABLE a (a INTEGER);\n',
     '1.test.down.sql': 'DROP TABLE a;\n'
   }
 }));
    it("errors on bad package.json's", () => {
      const pkg = {
        name: "foo",
        version: "1.0.0",
      };

      mock({
        "node_modules": {
          bad: {
            "package.json": "THIS_IS_NOT_JSON",
          },
        },
        "package.json": JSON.stringify(pkg),
      });

      return readPackages(".")
        .then(_resolvePackageMap)
        .then(() => {
          throw new Error("Should not reach then");
        })
        .catch((err) => {
          expect(err)
            .to.be.an.instanceOf(SyntaxError).and
            .to.have.property("message").that.contains("Unexpected token");
        });
    });