DEV Community

suhhee1011
suhhee1011

Posted on

Github action and create test case on other's repo

For this lab, I needed to create a GitHub action for my SSG project and add a new test case for the other classmate's project.
First, I worked on my SSG project first so that other classmates can add their test cases if needed. And I followed a lecture on how to create the GitHub action. Creating GitHub action was very straightforward and simple work. And while I am working on this, I noticed that I saw this when I was working on the external open-source projects and it was a bit annoying to me haha. However, now I know that how it works and it will prevent the crashing of my project.
This is the github action that I created

# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - name: run ci
    - run: npm ci
    - name: run test
    - run: npm run test
Enter fullscreen mode Exit fullscreen mode

After that, I go to Minsu's GitHub repository and work on his SSG project. I chose it because I thought it is familiar to me. But I noticed that the project changed a lot. So I needed some time to read and understand his markdown instruction files. Once it runs, I start to look for the test cases that were missed. I found one part missed testing and it was validating metadata. So I added a test case to validate the Metadata function. And I pushed to my forked repository and create a pull request on his main repository. However, it caused an error on formatter and eslint. So, I run the two commands to format it and pushed it again. And finally, GitHub action passed my pull request and Minsu merged it on his GitHub.

//In IWrapper.cs
string WrapGenerateInterporatedstring(string title, string style, string body, string meta)
        {
            return Helpers.GenerateInterporatedstring(title, style, body, meta);
        }

//In UnitTest.cs
        [Fact]
        public void GenerateMetaTest()
        {
            var mock = new Mock<IWrapper>();
            string title = "test";
            string style = "none";
            string body = "<div></div>";
            string meta = "ssg";

            // expected
            mock.Setup(x => x.WrapGenerateInterporatedstring(title, style, body, meta)).Returns(It.IsAny<string>());

            IWrapper obj = mock.Object;
            string result = obj.WrapGenerateInterporatedstring(title, style, body, meta);

            Assert.Equal(It.IsAny<string>(), result);
        }

Enter fullscreen mode Exit fullscreen mode

And I saw his GitHub action page to check if my code runs well, even though he used a different language from me. The format of his Github action and my GitHub action seems similar. This is his Github action.

name: .NET

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Install dependencies
      run: dotnet build ./kimchi-ssg/kimchi-ssg.csproj
    - name: Run Formatter & Linter
      run: |
        dotnet tool install --global dotnet-format --version 5.1.250
        dotnet-format --check --folder ./kimchi-ssg
    - name: Test
      run: dotnet test ./UnitTest/UnitTest.csproj
Enter fullscreen mode Exit fullscreen mode

This lab doesn't take a long time but it gives enough experience to prevent me or others to crash on the project I can apply to my next real project.

Top comments (0)