Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update dependency vite to ^4.3.9 #419

Open
wants to merge 12 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: test

on:
push:
paths-ignore:
- 'docs/**'
- 'playground/**'
- 'examples/**'

pull_request:
paths-ignore:
- 'docs/**'
- 'playground/**'
- 'examples/**'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm run lint

- name: Types
run: pnpm run test:types

- name: Test
run: pnpm run test:unit

- name: Build
run: pnpm run build

- name: Build dts
run: pnpm run build:dts

- name: Size
run: pnpm run size

- uses: codecov/codecov-action@v2
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
24 changes: 17 additions & 7 deletions __tests__/Promised.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
// @vitest-environment jsdom
/* eslint-disable no-unused-vars */
import { mount } from '@vue/test-utils'
import { mockWarn } from 'jest-mock-warn'
import { PromisedImpl as Promised } from '../src/Promised'
import fakePromise from 'faked-promise'
import { h } from 'vue'
import {
describe,
it,
expect,
beforeEach,
afterEach,
afterAll,
vi,
} from 'vitest'
import { mockWarn } from './vitest-mock-warn'

// keep a real setTimeout
const timeout = setTimeout
Expand Down Expand Up @@ -95,9 +105,9 @@ describe('Promised', () => {

describe('three slots pendingDelay', () => {
beforeEach(() => {
jest.useFakeTimers('modern')
jest.spyOn(global, 'setTimeout')
jest.spyOn(global, 'clearTimeout')
vi.useFakeTimers()
vi.spyOn(global, 'setTimeout')
vi.spyOn(global, 'clearTimeout')
})
afterEach(() => {
// @ts-expect-error: mocked
Expand All @@ -107,13 +117,13 @@ describe('Promised', () => {
})

afterAll(() => {
jest.useRealTimers()
vi.useRealTimers()
})

it('displays nothing before the delay', async () => {
let { wrapper } = factory({ pendingDelay: 300 })
expect(wrapper.text()).toBe('')
jest.runAllTimers()
vi.runAllTimers()
await wrapper.vm.$nextTick()
expect(wrapper.text()).toMatch('pending')
})
Expand Down Expand Up @@ -206,6 +216,6 @@ describe('Promised', () => {
reject(new Error())
await tick()

expect('Missing slot "rejected"').toHaveBeenWarned()
expect(/Missing slot "rejected"/).toHaveBeenWarned()
})
})
10 changes: 5 additions & 5 deletions __tests__/__snapshots__/Promised.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Promised combined slot displays the data 1`] = `"<span>{\\"isPending\\":true,\\"isRejected\\":false,\\"isResolved\\":false,\\"isDelayElapsed\\":true,\\"error\\":null}</span>"`;
exports[`Promised > combined slot > displays the data 1`] = `"<span>{\\"isPending\\":true,\\"isRejected\\":false,\\"isResolved\\":false,\\"isDelayElapsed\\":true,\\"error\\":null}</span>"`;

exports[`Promised combined slot displays the data 2`] = `"<span>{\\"isPending\\":false,\\"isRejected\\":false,\\"isResolved\\":true,\\"isDelayElapsed\\":true,\\"error\\":null,\\"data\\":\\"foo\\"}</span>"`;
exports[`Promised > combined slot > displays the data 2`] = `"<span>{\\"isPending\\":false,\\"isRejected\\":false,\\"isResolved\\":true,\\"isDelayElapsed\\":true,\\"error\\":null,\\"data\\":\\"foo\\"}</span>"`;

exports[`Promised combined slot displays the error 1`] = `"<span>{\\"isPending\\":true,\\"isRejected\\":false,\\"isResolved\\":false,\\"isDelayElapsed\\":true,\\"error\\":null}</span>"`;
exports[`Promised > combined slot > displays the error 1`] = `"<span>{\\"isPending\\":true,\\"isRejected\\":false,\\"isResolved\\":false,\\"isDelayElapsed\\":true,\\"error\\":null}</span>"`;

exports[`Promised combined slot displays the error 2`] = `"<span>{\\"isPending\\":false,\\"isRejected\\":true,\\"isResolved\\":false,\\"isDelayElapsed\\":true,\\"error\\":{}}</span>"`;
exports[`Promised > combined slot > displays the error 2`] = `"<span>{\\"isPending\\":false,\\"isRejected\\":true,\\"isResolved\\":false,\\"isDelayElapsed\\":true,\\"error\\":{}}</span>"`;
129 changes: 129 additions & 0 deletions __tests__/vitest-mock-warn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// https://github.com/posva/jest-mock-warn/blob/master/src/index.js

import { afterEach, beforeEach, expect, SpyInstance, vi } from 'vitest'

interface CustomMatchers<R = unknown> {
toHaveBeenWarned(): R
toHaveBeenWarnedLast(): R
toHaveBeenWarnedTimes(n: number): R
}

declare module 'vitest' {
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
}

export function mockWarn() {
expect.extend({
toHaveBeenWarned(received: string | RegExp) {
asserted.set(received.toString(), received)
const passed = warn.mock.calls.some((args) =>
typeof received === 'string'
? args[0].indexOf(received) > -1
: received.test(args[0])
)
if (passed) {
return {
pass: true,
message: () => `expected "${received}" not to have been warned.`,
}
} else {
const msgs = warn.mock.calls.map((args) => args[0]).join('\n - ')
return {
pass: false,
message: () =>
`expected "${received}" to have been warned.\n\nActual messages:\n\n - ${msgs}`,
}
}
},

toHaveBeenWarnedLast(received: string | RegExp) {
asserted.set(received.toString(), received)
const lastCall = warn.mock.calls[warn.mock.calls.length - 1][0]
const passed =
typeof received === 'string'
? lastCall.indexOf(received) > -1
: received.test(lastCall)
if (passed) {
return {
pass: true,
message: () => `expected "${received}" not to have been warned last.`,
}
} else {
const msgs = warn.mock.calls.map((args) => args[0]).join('\n - ')
return {
pass: false,
message: () =>
`expected "${received}" to have been warned last.\n\nActual messages:\n\n - ${msgs}`,
}
}
},

toHaveBeenWarnedTimes(received: string | RegExp, n: number) {
asserted.set(received.toString(), received)
let found = 0
warn.mock.calls.forEach((args) => {
const isFound =
typeof received === 'string'
? args[0].indexOf(received) > -1
: received.test(args[0])
if (isFound) {
found++
}
})

if (found === n) {
return {
pass: true,
message: () =>
`expected "${received}" to have been warned ${n} times.`,
}
} else {
return {
pass: false,
message: () =>
`expected "${received}" to have been warned ${n} times but got ${found}.`,
}
}
},
})

let warn: SpyInstance
const asserted = new Map<string, string | RegExp>()

beforeEach(() => {
asserted.clear()
warn = vi.spyOn(console, 'warn')
warn.mockImplementation(() => {})
})

afterEach(() => {
const assertedArray = Array.from(asserted)
const nonAssertedWarnings = warn.mock.calls
.map((args) => args[0])
.filter((received) => {
return !assertedArray.some(([key, assertedMsg]) => {
return typeof assertedMsg === 'string'
? received.indexOf(assertedMsg) > -1
: assertedMsg.test(received)
})
})
warn.mockRestore()
if (nonAssertedWarnings.length) {
nonAssertedWarnings.forEach((warning) => {
console.warn(warning)
})
throw new Error(`test case threw unexpected warnings.`)
}
})
}

declare global {
namespace Vi {
interface JestAssertion<T = any> {
toHaveBeenWarned(): void
toHaveBeenWarnedLast(): void
toHaveBeenWarnedTimes(n: number): void
}
}
}
29 changes: 0 additions & 29 deletions circle.yml

This file was deleted.

Loading