Skip to content

Commit df7a4b3

Browse files
committed
npm run fix
1 parent e675a6a commit df7a4b3

16 files changed

+109
-103
lines changed

__mocks__/@line/liff.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Liff } from '@line/liff';
1+
import { Liff } from "@line/liff";
22

3-
type IdWritableLiff = Omit<Liff, 'id'> & { id: string | null };
3+
type IdWritableLiff = Omit<Liff, "id"> & { id: string | null };
44

55
let loginState = false;
66

examples/simple/src/App.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { useEffect, useState } from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
1+
import React, { useEffect, useState } from "react";
2+
import "./App.css";
3+
import logo from "./logo.svg";
44

5-
import { useLiff } from 'react-liff';
5+
import { useLiff } from "react-liff";
66

77
function App() {
88
const { error, isLoggedIn, isReady, liff } = useLiff();
9-
const [displayName, setDisplayName] = useState('');
9+
const [displayName, setDisplayName] = useState("");
1010

1111
useEffect(() => {
1212
if (!isLoggedIn) return;
@@ -29,15 +29,21 @@ function App() {
2929
if (!isReady) return <p>Loading...</p>;
3030

3131
if (!isLoggedIn) {
32-
return <button className="App-button" onClick={loginHandler}>Login</button>;
32+
return (
33+
<button className="App-button" onClick={loginHandler}>
34+
Login
35+
</button>
36+
);
3337
}
3438
return (
3539
<>
3640
<p>Welcome to the react-liff demo app, {displayName}!</p>
37-
<button className="App-button" onClick={logoutHandler}>Logout</button>
41+
<button className="App-button" onClick={logoutHandler}>
42+
Logout
43+
</button>
3844
</>
3945
);
40-
}
46+
};
4147

4248
return (
4349
<div className="App">

examples/simple/src/index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { LiffMockPlugin } from '@line/liff-mock';
2-
import { StrictMode } from 'react';
3-
import { createRoot } from 'react-dom/client';
4-
import './index.css';
5-
import App from './App';
1+
import { LiffMockPlugin } from "@line/liff-mock";
2+
import { StrictMode } from "react";
3+
import { createRoot } from "react-dom/client";
4+
import App from "./App";
5+
import "./index.css";
66

7-
import { LiffProvider } from 'react-liff';
7+
import { LiffProvider } from "react-liff";
88

9-
const liffId = process.env.REACT_APP_LINE_LIFF_ID ?? '';
10-
const mockEnabled = process.env.NODE_ENV !== 'production';
9+
const liffId = process.env.REACT_APP_LINE_LIFF_ID ?? "";
10+
const mockEnabled = process.env.NODE_ENV !== "production";
1111
const liffPlugins = [new LiffMockPlugin()];
1212

13-
const root = createRoot(document.getElementById('root'));
13+
const root = createRoot(document.getElementById("root"));
1414
root.render(
1515
<StrictMode>
1616
<LiffProvider liffId={liffId} mock={mockEnabled} plugins={liffPlugins}>
1717
<App />
1818
</LiffProvider>
19-
</StrictMode>
19+
</StrictMode>,
2020
);

jest.config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export default {
2-
collectCoverageFrom: ['<rootDir>/src/**/*.ts{,x}', '!<rootDir>/src/**/*.test.ts{,x}'],
2+
collectCoverageFrom: ["<rootDir>/src/**/*.ts{,x}", "!<rootDir>/src/**/*.test.ts{,x}"],
33
moduleNameMapper: {
4-
'^(\\.{1,2}/.*)\\.js$': '$1',
4+
"^(\\.{1,2}/.*)\\.js$": "$1",
55
},
6-
preset: 'ts-jest/presets/default-esm',
7-
testEnvironment: 'jsdom',
6+
preset: "ts-jest/presets/default-esm",
7+
testEnvironment: "jsdom",
88
transform: {
9-
'\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.test.json', useESM: true }],
9+
"\\.tsx?$": ["ts-jest", { tsconfig: "tsconfig.test.json", useESM: true }],
1010
},
1111
};

src/context/create-liff-context.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { Liff } from '@line/liff';
2-
import { createContext, useContext } from 'react';
1+
import { Liff } from "@line/liff";
2+
import { createContext, useContext } from "react";
33

4-
import { createLiffProvider } from './create-liff-provider.js';
5-
import { CreateLiffContext, LiffContextStates } from './types.js';
4+
import { createLiffProvider } from "./create-liff-provider.js";
5+
import { CreateLiffContext, LiffContextStates } from "./types.js";
66

77
export const createLiffContext: CreateLiffContext = () => {
88
const context = createContext<LiffContextStates>({
99
isLoggedIn: false,
1010
isReady: false,
1111
liff: {} as Liff,
1212
});
13-
context.displayName = 'LiffContext';
13+
context.displayName = "LiffContext";
1414

1515
return {
1616
LiffConsumer: context.Consumer,

src/context/create-liff-provider.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Liff } from '@line/liff';
2-
import * as PropTypes from 'prop-types';
3-
import { createElement, FC, useEffect, useState } from 'react';
1+
import { Liff } from "@line/liff";
2+
import * as PropTypes from "prop-types";
3+
import { FC, createElement, useEffect, useState } from "react";
44

5-
import { useLoginStateManager } from '../hooks/index.js';
6-
import { getInitializedLiff } from '../lib/index.js';
5+
import { useLoginStateManager } from "../hooks/index.js";
6+
import { getInitializedLiff } from "../lib/index.js";
77

8-
import { CreateLiffProvider, LiffProviderProps } from './types.js';
8+
import { CreateLiffProvider, LiffProviderProps } from "./types.js";
99

1010
const LiffProviderPropTypes = {
1111
children: PropTypes.element.isRequired,
@@ -15,7 +15,7 @@ const LiffProviderPropTypes = {
1515
callback: PropTypes.func,
1616
};
1717

18-
export const createLiffProvider: CreateLiffProvider = context => {
18+
export const createLiffProvider: CreateLiffProvider = (context) => {
1919
const LiffProvider: FC<LiffProviderProps> = ({ children, ...rest }) => {
2020
const [error, setError] = useState<unknown>();
2121
const [isReady, setIsReady] = useState(false);

src/context/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { createLiffContext } from './create-liff-context.js';
1+
import { createLiffContext } from "./create-liff-context.js";
22

33
export const { LiffConsumer, LiffProvider, useLiff } = createLiffContext();

src/context/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Liff } from '@line/liff';
2-
import type { Consumer, Context, FC, ReactNode } from 'react';
1+
import type { Liff } from "@line/liff";
2+
import type { Consumer, Context, FC, ReactNode } from "react";
33

4-
import type { GetInitializedLiffProps } from '../lib/index.js';
4+
import type { GetInitializedLiffProps } from "../lib/index.js";
55

66
export interface CreateLiffContext {
77
(): {

src/hooks/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { useLoginStateManager } from './use-login-state-manager.js';
1+
export { useLoginStateManager } from "./use-login-state-manager.js";

src/hooks/use-login-state-manager.test.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { default as liff } from '@line/liff';
2-
import { act, renderHook } from '@testing-library/react';
1+
import { default as liff } from "@line/liff";
2+
import { act, renderHook } from "@testing-library/react";
33

4-
import { useLoginStateManager } from './use-login-state-manager';
4+
import { useLoginStateManager } from "./use-login-state-manager";
55

6-
jest.mock('@line/liff');
6+
jest.mock("@line/liff");
77

8-
describe('useLoginStateManager', () => {
9-
describe('When liff is undefined', () => {
8+
describe("useLoginStateManager", () => {
9+
describe("When liff is undefined", () => {
1010
const render = () => renderHook(() => useLoginStateManager(undefined));
1111

12-
describe('After the hook is initialized', () => {
13-
it('return false as initial login state', () => {
12+
describe("After the hook is initialized", () => {
13+
it("return false as initial login state", () => {
1414
const { result } = render();
1515

1616
expect(result.current[0]).toBe(false);
1717
});
1818
});
1919

20-
describe('After `login()` was called', () => {
21-
it('return false as login state', () => {
20+
describe("After `login()` was called", () => {
21+
it("return false as login state", () => {
2222
const { result } = render();
2323

2424
act(() => {
@@ -29,8 +29,8 @@ describe('useLoginStateManager', () => {
2929
});
3030
});
3131

32-
describe('After `logout()` was called', () => {
33-
it('return true as login state', () => {
32+
describe("After `logout()` was called", () => {
33+
it("return true as login state", () => {
3434
const { result } = render();
3535

3636
act(() => {
@@ -42,19 +42,19 @@ describe('useLoginStateManager', () => {
4242
});
4343
});
4444

45-
describe('When liff is defined', () => {
45+
describe("When liff is defined", () => {
4646
const render = () => renderHook(() => useLoginStateManager(liff));
4747

48-
describe('After the hook is initialized', () => {
49-
it('return false as initial login state', () => {
48+
describe("After the hook is initialized", () => {
49+
it("return false as initial login state", () => {
5050
const { result } = render();
5151

5252
expect(result.current[0]).toBe(false);
5353
});
5454
});
5555

56-
describe('After `login()` was called', () => {
57-
it('return true as login state', () => {
56+
describe("After `login()` was called", () => {
57+
it("return true as login state", () => {
5858
const { result } = render();
5959

6060
act(() => {
@@ -65,8 +65,8 @@ describe('useLoginStateManager', () => {
6565
});
6666
});
6767

68-
describe('After `logout()` was called', () => {
69-
it('return true as login state', () => {
68+
describe("After `logout()` was called", () => {
69+
it("return true as login state", () => {
7070
const { result } = render();
7171

7272
act(() => {

src/hooks/use-login-state-manager.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Liff } from '@line/liff';
2-
import { useEffect, useState } from 'react';
1+
import { Liff } from "@line/liff";
2+
import { useEffect, useState } from "react";
33

44
export const useLoginStateManager = (liff: Liff | undefined): [boolean, Liff] => {
55
const { isLoggedIn = () => false, login = () => {}, logout = () => {}, ...rest } = liff ?? {};
@@ -9,11 +9,11 @@ export const useLoginStateManager = (liff: Liff | undefined): [boolean, Liff] =>
99
setLoginState(isLoggedIn());
1010
}, [isLoggedIn]);
1111

12-
const customLogin: Liff['login'] = (...args) => {
12+
const customLogin: Liff["login"] = (...args) => {
1313
login(...args);
1414
setLoginState(isLoggedIn());
1515
};
16-
const customLogout: Liff['logout'] = () => {
16+
const customLogout: Liff["logout"] = () => {
1717
logout();
1818
setLoginState(isLoggedIn());
1919
};

src/index.test.tsx

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { default as liff } from '@line/liff';
2-
import { render, waitFor } from '@testing-library/react';
1+
import { default as liff } from "@line/liff";
2+
import { render, waitFor } from "@testing-library/react";
33

4-
import { LiffProvider, useLiff } from '.';
4+
import { LiffProvider, useLiff } from ".";
55

6-
jest.mock('@line/liff');
6+
jest.mock("@line/liff");
77

88
const TestComponent = () => {
99
const LiffConsumer = () => {
@@ -19,38 +19,38 @@ const TestComponent = () => {
1919
};
2020

2121
return (
22-
<LiffProvider liffId={'myLiffId'}>
22+
<LiffProvider liffId={"myLiffId"}>
2323
<LiffConsumer />
2424
</LiffProvider>
2525
);
2626
};
2727

28-
describe('LiffProvider', () => {
29-
describe('When the `liff.init()` succeeds', () => {
30-
it('shows myLiffId', async () => {
28+
describe("LiffProvider", () => {
29+
describe("When the `liff.init()` succeeds", () => {
30+
it("shows myLiffId", async () => {
3131
const { getByTestId } = render(TestComponent());
3232

3333
await waitFor(() => {
34-
expect(getByTestId('isReady').textContent).toBe('true');
35-
expect(getByTestId('error.message').textContent).toBe('');
36-
expect(getByTestId('liff.id').textContent).toBe('myLiffId');
34+
expect(getByTestId("isReady").textContent).toBe("true");
35+
expect(getByTestId("error.message").textContent).toBe("");
36+
expect(getByTestId("liff.id").textContent).toBe("myLiffId");
3737
});
3838
});
3939
});
4040

41-
describe('When the `liff.init()` failed', () => {
41+
describe("When the `liff.init()` failed", () => {
4242
beforeEach(() => {
4343
liff.init = jest.fn().mockImplementationOnce(async () => {
44-
throw new Error('Failed to initialize liff.');
44+
throw new Error("Failed to initialize liff.");
4545
});
4646
});
4747

48-
it('shows error message', async () => {
48+
it("shows error message", async () => {
4949
const { getByTestId } = render(TestComponent());
5050

5151
await waitFor(() => {
52-
expect(getByTestId('isReady').textContent).toBe('false');
53-
expect(getByTestId('error.message').textContent).toBe('Failed to initialize liff.');
52+
expect(getByTestId("isReady").textContent).toBe("false");
53+
expect(getByTestId("error.message").textContent).toBe("Failed to initialize liff.");
5454
});
5555
});
5656
});

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './context/index.js';
1+
export * from "./context/index.js";

0 commit comments

Comments
 (0)