コード例 #1
0
ファイル: init.test.js プロジェクト: facebook/jest
      it('user answered with "No"', async () => {
        prompts.mockReturnValueOnce({continue: false});

        await init(resolveFromFixture('has_jest_config_file'));
        // return after first prompt
        expect(prompts).toHaveBeenCalledTimes(1);
      });
コード例 #2
0
ファイル: init.test.js プロジェクト: whatknight/jest
    it('should ask "typescript question" when has typescript in devDependencies', async () => {
      prompts.mockReturnValueOnce({});

      await init(resolveFromFixture('typescript_in_dev_dependencies'));

      const typescriptQuestion = prompts.mock.calls[0][0][0];

      expect(typescriptQuestion).toMatchSnapshot();
    });
コード例 #3
0
ファイル: init.test.js プロジェクト: facebook/jest
      it('should create package.json with configured test command when {scripts: true}', async () => {
        prompts.mockReturnValueOnce({scripts: true});

        await init(resolveFromFixture('only_package_json'));

        const writtenPackageJson = fs.writeFileSync.mock.calls[0][1];

        expect(writtenPackageJson).toMatchSnapshot();
        expect(JSON.parse(writtenPackageJson).scripts.test).toEqual('jest');
      });
コード例 #4
0
ファイル: init.test.js プロジェクト: facebook/jest
      it('should create configuration for {environment: "node"}', async () => {
        prompts.mockReturnValueOnce({environment: 'node'});

        await init(resolveFromFixture('only_package_json'));

        const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
        const evaluatedConfig = eval(writtenJestConfig);
        // should modify when the default environment will be changed to "node"
        expect(evaluatedConfig).toEqual({testEnvironment: 'node'});
      });
コード例 #5
0
ファイル: init.test.js プロジェクト: facebook/jest
      it('should create configuration for {coverage: true}', async () => {
        prompts.mockReturnValueOnce({coverage: true});

        await init(resolveFromFixture('only_package_json'));

        const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
        const evaluatedConfig = eval(writtenJestConfig);

        expect(evaluatedConfig).toEqual({coverageDirectory: 'coverage'});
      });
コード例 #6
0
ファイル: init.test.js プロジェクト: whatknight/jest
    it('should create configuration for {typescript: true}', async () => {
      prompts.mockReturnValueOnce({typescript: true});

      await init(resolveFromFixture('typescript_in_dev_dependencies'));

      const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];
      const evaluatedConfig = eval(writtenJestConfig);

      expect(evaluatedConfig).toMatchSnapshot();
    });
コード例 #7
0
ファイル: init.test.js プロジェクト: facebook/jest
    it('should not ask "test script question"', async () => {
      prompts.mockReturnValueOnce({});

      await init(resolveFromFixture('test_script_configured'));

      const questionsNames = prompts.mock.calls[0][0].map(
        question => question.name,
      );

      expect(questionsNames).not.toContain('scripts');
    });
コード例 #8
0
ファイル: init.test.js プロジェクト: facebook/jest
    it('should ask the user whether to override config or not', async () => {
      prompts.mockReturnValueOnce({continue: true}).mockReturnValueOnce({});

      await init(resolveFromFixture('has_jest_config_in_package_json'));

      expect(prompts.mock.calls[0][0]).toMatchSnapshot();

      const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];

      expect(writtenJestConfig).toBeDefined();
    });
コード例 #9
0
ファイル: init.test.js プロジェクト: facebook/jest
      it('user answered with "Yes"', async () => {
        prompts.mockReturnValueOnce({continue: true}).mockReturnValueOnce({});

        await init(resolveFromFixture('has_jest_config_file'));

        expect(prompts.mock.calls[0][0]).toMatchSnapshot();

        const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];

        expect(writtenJestConfig).toBeDefined();
      });
コード例 #10
0
ファイル: init.test.js プロジェクト: facebook/jest
      it('should return the default configuration (an empty config)', async () => {
        prompts.mockReturnValueOnce({});

        await init(resolveFromFixture('only_package_json'));

        const writtenJestConfig = fs.writeFileSync.mock.calls[0][1];

        expect(writtenJestConfig).toMatchSnapshot();

        const evaluatedConfig = eval(writtenJestConfig);

        expect(evaluatedConfig).toEqual({});
      });