Skip to content

Commit

Permalink
Feature/#220 iframe support (#315)
Browse files Browse the repository at this point in the history
* Refactored Virtual DOM structure
* Added new E2E tests
* Updated E2E Test Runner
  • Loading branch information
ziflex authored Jun 19, 2019
1 parent 8c07516 commit d7b923e
Show file tree
Hide file tree
Showing 103 changed files with 2,753 additions and 1,567 deletions.
33 changes: 33 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file contains all available configuration options
# with their default values.

# options for analysis running
run:
# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- pkg/parser/fql
- pkg/parser/antlr

linters:
disable:
- errcheck

issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- '^(G104|G401|G505|G501):'
- '^shadow: declaration of'

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- "*_test.go"
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ addons:

install:
- go get -u github.com/mgechev/revive
- go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
- sudo curl -o /usr/local/lib/antlr-4.7.1-complete.jar https://www.antlr.org/download/antlr-4.7.1-complete.jar
- export CLASSPATH=".:/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH"
- mkdir $HOME/travis-bin
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cover:
curl -s https://codecov.io/bash | bash

e2e:
go run ${DIR_E2E}/main.go --tests ${DIR_E2E}/tests --pages ${DIR_E2E}/pages --filter doc_cookie_set*
go run ${DIR_E2E}/main.go --tests ${DIR_E2E}/tests --pages ${DIR_E2E}/pages

bench:
go test -run=XXX -bench=. ${DIR_PKG}/...
Expand All @@ -48,7 +48,8 @@ fmt:
# https://github.com/mgechev/revive
# go get github.com/mgechev/revive
lint:
revive -config revive.toml -formatter friendly -exclude ./pkg/parser/fql/... -exclude ./vendor/... ./...
revive -config revive.toml -formatter friendly -exclude ./pkg/parser/fql/... -exclude ./vendor/... ./... && \
golangci-lint run ./pkg/...

# http://godoc.org/code.google.com/p/go.tools/cmd/vet
# go get code.google.com/p/go.tools/cmd/vet
Expand Down
58 changes: 37 additions & 21 deletions e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"context"
"flag"
"fmt"
"github.com/MontFerret/ferret/e2e/runner"
"github.com/MontFerret/ferret/e2e/server"
"github.com/rs/zerolog"
"net"
"os"
"os/signal"
"path/filepath"
"regexp"

"github.com/MontFerret/ferret/e2e/runner"
"github.com/MontFerret/ferret/e2e/server"

"github.com/rs/zerolog"
)

var (
Expand Down Expand Up @@ -39,6 +41,20 @@ var (
)
)

func getOutboundIP() (net.IP, error) {
conn, err := net.Dial("udp", "8.8.8.8:80")

if err != nil {
return nil, err
}

defer conn.Close()

localAddr := conn.LocalAddr().(*net.UDPAddr)

return localAddr.IP, nil
}

func main() {
flag.Parse()

Expand All @@ -56,19 +72,6 @@ func main() {
Dir: filepath.Join(*pagesDir, "dynamic"),
})

var filterR *regexp.Regexp

if *filter != "" {
r, err := regexp.Compile(*filter)

if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

filterR = r
}

go func() {
if err := static.Start(); err != nil {
logger.Info().Timestamp().Msg("shutting down the static pages server")
Expand All @@ -91,12 +94,25 @@ func main() {
}
}

var ipAddr string

// we need it in those cases when a Chrome instance is running inside a container
// and it needs an external IP to get access to our static web server
outIP, err := getOutboundIP()

if err != nil {
ipAddr = "0.0.0.0"
logger.Warn().Err(err).Msg("Failed to get outbound IP address")
} else {
ipAddr = outIP.String()
}

r := runner.New(logger, runner.Settings{
StaticServerAddress: fmt.Sprintf("http://0.0.0.0:%d", staticPort),
DynamicServerAddress: fmt.Sprintf("http://0.0.0.0:%d", dynamicPort),
StaticServerAddress: fmt.Sprintf("http://%s:%d", ipAddr, staticPort),
DynamicServerAddress: fmt.Sprintf("http://%s:%d", ipAddr, dynamicPort),
CDPAddress: *cdp,
Dir: *testsDir,
Filter: filterR,
Filter: *filter,
})

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -110,7 +126,7 @@ func main() {
}
}()

err := r.Run(ctx)
err = r.Run(ctx)

if err != nil {
os.Exit(1)
Expand Down
30 changes: 27 additions & 3 deletions e2e/pages/dynamic/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Layout from './layout.js';
import IndexPage from './pages/index.js';
import FormsPage from './pages/forms/index.js';
import EventsPage from './pages/events/index.js';
import IframePage from './pages/iframes/index.js';

const e = React.createElement;
const Router = ReactRouter.Router;
Expand All @@ -10,7 +11,26 @@ const Route = ReactRouter.Route;
const Redirect = ReactRouter.Redirect;
const createBrowserHistory = History.createBrowserHistory;

export default function AppComponent({ redirect = null}) {
export default React.memo(function AppComponent(params = {}) {
let redirectTo;

if (params.redirect) {
let search = '';

Object.keys(params).forEach((key) => {
if (key !== 'redirect') {
search += `${key}=${params[key]}`;
}
});

const to = {
pathname: params.redirect,
search: search ? `?${search}` : '',
};

redirectTo = e(Redirect, { to });
}

return e(Router, { history: createBrowserHistory() },
e(Layout, null, [
e(Switch, null, [
Expand All @@ -27,8 +47,12 @@ export default function AppComponent({ redirect = null}) {
path: '/events',
component: EventsPage
}),
e(Route, {
path: '/iframe',
component: IframePage
}),
]),
redirect ? e(Redirect, { to: redirect }) : null
redirectTo
])
)
}
})
3 changes: 3 additions & 0 deletions e2e/pages/dynamic/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default function Layout({ children }) {
]),
e("li", { className: "nav-item"}, [
e(NavLink, { className: "nav-link", to: "/events" }, "Events")
]),
e("li", { className: "nav-item"}, [
e(NavLink, { className: "nav-link", to: "/iframe" }, "iFrame")
])
])
])
Expand Down
26 changes: 26 additions & 0 deletions e2e/pages/dynamic/components/pages/iframes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { parse } from '../../../utils/qs.js';

const e = React.createElement;

export default class IFramePage extends React.Component {
render() {
const search = parse(this.props.location.search);

let redirect;

if (search.src) {
redirect = search.src;
}

return e("div", { id: "iframe" }, [
e("iframe", {
name: 'nested',
style: {
width: '100%',
height: '800px',
},
src: redirect ? `/?redirect=${redirect}` : '/'
}),
])
}
}
6 changes: 3 additions & 3 deletions e2e/pages/dynamic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</head>
<body class="text-center">
<div id="root"></div>
<script src="https://unpkg.com/react@16.6.1/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16.6.1/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/history@4.7.2/umd/history.min.js"></script>
<script src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/history@4.9.0/umd/history.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-router.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-router-dom.js"></script>
<script src="index.js" type="module"></script>
Expand Down
Loading

0 comments on commit d7b923e

Please sign in to comment.