github.com/saucelabs/saucectl@v0.175.1/internal/cypress/grep/grep_test.go (about)

     1  package grep
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  	"testing/fstest"
     7  )
     8  
     9  func TestMatchFiles(t *testing.T) {
    10  	mockFS := fstest.MapFS{
    11  		"spec1.js": {
    12  			Data: []byte(`
    13  context('Actions', () => {
    14    beforeEach(() => {
    15      cy.visit('https://example.cypress.io/commands/actions')
    16    })
    17    it('.type() - type into a DOM element', { tags: ['@smoke'] }, () => {
    18      // https://on.cypress.io/type
    19      cy.get('.action-email')
    20          .type('fake@email.com').should('have.value', 'fake@email.com')
    21    })
    22  
    23    it('.focus() - focus on a DOM element', { tags: '@flakey' }, () => {
    24      // https://on.cypress.io/focus
    25        cy.get('.action-focus').focus()
    26          .should('have.class', 'focus')
    27          .prev().should('have.attr', 'style', 'color: orange;');
    28      }
    29    );
    30  })
    31  `),
    32  		},
    33  		"spec2.js": {
    34  			Data: []byte(`
    35  context('Assertions', () => {
    36    beforeEach(() => {
    37      cy.visit('https://example.cypress.io/commands/assertions')
    38    })
    39    it('.and() - chain multiple assertions together', {tags: ['@smoke', '@flakey']}, () => {
    40      cy.get('.assertions-link')
    41      .should('have.class', 'active')
    42      .and('have.attr', 'href')
    43      .and('include', 'cypress.io')
    44    })
    45  })
    46  `),
    47  		},
    48  	}
    49  
    50  	matched, unmatched := MatchFiles(mockFS, []string{"spec1.js", "spec2.js"}, "", "@flakey")
    51  
    52  	got := len(matched) + len(unmatched)
    53  	want := len(mockFS)
    54  	if got != want {
    55  		t.Errorf("The returned slices from Match should not have duplicate values: got(%d) want(%d)", got, want)
    56  	}
    57  
    58  	wantMatch := []string{"spec1.js", "spec2.js"}
    59  	if !reflect.DeepEqual(matched, wantMatch) {
    60  		t.Errorf("MatchFiles() matched got = (%s) want = (%s)", matched, wantMatch)
    61  	}
    62  
    63  	wantUnmatched := []string(nil)
    64  	if !reflect.DeepEqual(unmatched, wantUnmatched) {
    65  		t.Errorf("MatchFiles() unmatched got = (%s) want = (%s)", unmatched, wantUnmatched)
    66  	}
    67  }