Skip to content

Commit

Permalink
Merge branch 'main' into feat/vitest-no-identical-title
Browse files Browse the repository at this point in the history
  • Loading branch information
eryue0220 authored Jul 23, 2024
2 parents a309313 + 4246a21 commit 4e59b0a
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 119 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.ref_name != 'main' }}

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-D warnings"

jobs:
test:
name: Test
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/prepare_release_crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ concurrency:
cancel-in-progress: true

jobs:
prepare_release:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: taiki-e/checkout-action@v1
- uses: Boshen/setup-rust@main
with:
cache-key: warm
tools: cargo-release-oxc
- run: cargo ck
- run: cargo release-oxc publish --release crates --dry-run

prepare:
needs: check
name: Prepare Release Crates
uses: ./.github/workflows/reusable_prepare_release.yml
with:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/release_crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-D warnings"

jobs:
release:
name: Release crates
Expand Down
16 changes: 4 additions & 12 deletions .github/workflows/reusable_prepare_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ on:
version:
value: ${{ jobs.run.outputs.version }}

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-D warnings"

permissions:
pull-requests: write
contents: write
actions: write

jobs:
run:
name: Prepare Release
Expand All @@ -42,6 +33,7 @@ jobs:
- name: Run
id: run
run: |
cargo ck
cargo release-oxc update --release ${{ inputs.name }}
echo "VERSION=$(cat ./target/OXC_VERSION)" >> $GITHUB_OUTPUT
{
Expand All @@ -56,10 +48,10 @@ jobs:
- uses: peter-evans/create-pull-request@v6
id: pr
with:
token: ${{ secrets.GITHUB_TOKEN }}
# bot account with PAT required for triggering workflow runs
# See https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs
token: ${{ secrets.OXC_BOT_PAT }}
commit-message: Release ${{ inputs.name }}
committer: Boshen <Boshen@users.noreply.github.com>
author: Boshen <Boshen@users.noreply.github.com>
branch: release/${{ inputs.name }}
branch-suffix: timestamp
base: main
Expand Down
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 118 additions & 3 deletions crates/oxc_linter/src/rules/jest/no_conditional_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ declare_oxc_lint!(
// await foo().catch(error => expect(error).toBeInstanceOf(error));
// });
/// ```
///
/// This rule is compatible with [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest/blob/main/docs/rules/no-conditional-expect.md),
/// to use it, add the following configuration to your `.eslintrc.json`:
///
/// ```json
/// {
/// "rules": {
/// "vitest/no-conditional-expect": "error"
/// }
/// }
/// ```
NoConditionalExpect,
correctness
);
Expand Down Expand Up @@ -163,7 +174,7 @@ fn check_parents<'a>(
fn test() {
use crate::tester::Tester;

let pass = vec![
let mut pass = vec![
(
"
it('foo', () => {
Expand Down Expand Up @@ -431,7 +442,7 @@ fn test() {
),
];

let fail = vec![
let mut fail = vec![
(
"
it('foo', () => {
Expand Down Expand Up @@ -886,5 +897,109 @@ fn test() {
),
];

Tester::new(NoConditionalExpect::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
let pass_vitest = vec![
"
it('foo', () => {
process.env.FAIL && setNum(1);
expect(num).toBe(2);
});
",
"
function getValue() {
let num = 2;
process.env.FAIL && setNum(1);
return num;
}
it('foo', () => {
expect(getValue()).toBe(2);
});
",
"
function getValue() {
let num = 2;
process.env.FAIL || setNum(1);
return num;
}
it('foo', () => {
expect(getValue()).toBe(2);
});
",
"
it('foo', () => {
const num = process.env.FAIL ? 1 : 2;
expect(num).toBe(2);
});
",
"
function getValue() {
return process.env.FAIL ? 1 : 2
}
it('foo', () => {
expect(getValue()).toBe(2);
});
",
];

let fail_vitest = vec![
"
it('foo', () => {
something && expect(something).toHaveBeenCalled();
})
",
"
it('foo', () => {
a || (b && expect(something).toHaveBeenCalled());
})
",
"
it.each``('foo', () => {
something || expect(something).toHaveBeenCalled();
});
",
"
it.each()('foo', () => {
something || expect(something).toHaveBeenCalled();
})
",
"
function getValue() {
something || expect(something).toHaveBeenCalled();
}
it('foo', getValue);
",
"
it('foo', () => {
something ? expect(something).toHaveBeenCalled() : noop();
})
",
"
function getValue() {
something ? expect(something).toHaveBeenCalled() : noop();
}
it('foo', getValue);
",
"
it('foo', () => {
something ? noop() : expect(something).toHaveBeenCalled();
})
",
];

pass.extend(pass_vitest.into_iter().map(|x| (x, None)));
fail.extend(fail_vitest.into_iter().map(|x| (x, None)));

Tester::new(NoConditionalExpect::NAME, pass, fail)
.with_jest_plugin(true)
.with_vitest_plugin(true)
.test_and_snapshot();
}
Loading

0 comments on commit 4e59b0a

Please sign in to comment.